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.
It's not working because of the Mute
mode of your phone. To turn 'Mute On' in iOS 7, you have to follow the following steps:
Setting
optionAccessibility
AssistiveTouch
AssistiveTouch
option from the switch buttonDevice
and Touch Un mute
option.Now run the project and hope it will work.
P.S: (In iOS 8.0 this code wouldn't work, because for an unexpected bug, from iOS8.1 they remove it and it is now working perfectly) Hope it works. :)