Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVSpeechSynthesizer works on simulator but not on device

I've been trying to learn AVSpeechSynthesis. The code works fine in the iOS Simulator (both on iPad and iOS) but the text to speech feature doesn't work at all on my iPad. Here's my code.

    - (void)viewDidLoad
{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.



//Load Model
    self.string = @"Hello World";
    self.utterance = [[AVSpeechUtterance alloc] initWithString:self.string];
    self.utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
    self.utterance.rate = (float) 0.25;

    //Load UI
    self.textLabel.text = self.string;


}

- (IBAction)startSpeaking:(id)sender {

    self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init];

    if ([self.speechSynthesizer isSpeaking]) {

        [self.speechSynthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryWord];


    } else {

        [self.speechSynthesizer speakUtterance:self.utterance];

    }    
}

UPDATE: AVSpeechSyntheSizer is working but no sound So I have a UILabel with the same text as the AVSpeechUtterance on the UI. I implemented AVSpeechSynthesizerDelegate so that when I hit startSpeaking: the text label turns the current word red. So I know that AVSpeechSynthesizer must be working because it's making delegate calls but I can't figure out why I can't hear it. The volume is up and no other apps are playing audio.

like image 603
Daniel Lyons Avatar asked Jun 07 '14 03:06

Daniel Lyons


1 Answers

Do you have the phone in silent mode? That silences the synthesizer as well.

like image 80
jhosteny Avatar answered Oct 05 '22 12:10

jhosteny