Trying to run Sound and servo at same time

I am trying to combine my sound and servo. Either one or the other works.
this is my code

#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

void setup()
{
myservo.attach(3)
tmrpcm.speakerPin=9;
Serial.begin(9600);
if(!SD.begin(SD_ChipSelectPin))
{
  Serial.println("SD fail");
  return;
}
tmrpcm.setVolume(6);
tmrpcm.play("per.wav");

}

void loop() {
   {digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
  delay(1000);
   digitalWrite(7,LOW);
    digitalWrite(8,LOW);
     delay(1000);
    digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
   delay(1000);
}
  
   for (pos = 0; pos <= 180; pos += 1) {
     myservo.write(pos);              
    delay(65);  }  
  
 
     {digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
  delay(100);
   digitalWrite(7,LOW);
    digitalWrite(8,LOW);
     delay(100);
    digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
   delay(100);
     
}
  
  
  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);              
    delay(65); }
  {
   
  }
 

  

 digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
  delay(1000);
   digitalWrite(7,LOW);
    digitalWrite(8,LOW);
     delay(1000);
    digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
   delay(1000);

  
   for (pos = 0; pos <= 180; pos += 1) {
     myservo.write(pos);              
    delay(65);  }  
   {

  }
 
     {digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
  delay(100);
   digitalWrite(7,LOW);
    digitalWrite(8,LOW);
     delay(100);
      digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
  delay(100);
      
   
}
  
  
  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);              
    delay(65); }
  digitalWrite(7,HIGH);
   digitalWrite(8,HIGH);
  delay(100);
   digitalWrite(7,LOW);
    digitalWrite(8,LOW);
delay(100);

}

Servo library uses the register with pin 9. Pick another pin for your speaker.

I tried that but it didn't work.

Best to edit your sketch showing the revised pin. Or at least tell us what it is.

With AVR based Arduinos, the conflict is with timers (specifically, Timer1). Try the servoTimer2 library.

Okay