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.
Do you have the phone in silent mode? That silences the synthesizer as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With