2
votes

I am having problems using AVSpeechSynthesis on iOS 8.0.2 and XCode 5. I tried it on the simulator and got a "Speech initialization error: 2147483665". I then tried it on my iPhone 5 and got no error but no speech.

In my .h file I import

import

and have @property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;

In my .m file I synthesis the synthesizer

I have AVFoundation referenced in my frameworks

On my viewDidLoad I do the following

self.synthesizer = [[AVSpeechSynthesizer alloc] init]; self.synthesizer.delegate = self;

Later on in my code to control what is said I do the following

AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:dialog];
utterance.rate = AVSpeechUtteranceDefaultSpeechRate;
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-au"];
[self.synthesizer speakUtterance:utterance];

I have CCViewController : UIViewController in my view controller.

Does anyone know what is wrong? Does AVFoundation work in iOS 8?

I saw a similar post on stack overflow which said to initialize my speaking @" " but that did not work.

Any help would be appreciated.

Thanks, Greg

1
The 8.1 simulator does not do TTS. Download the 7.1 simulator and use it for testing.vijayst

1 Answers

2
votes

What you have should work with a small tweak, I think (see below), but only on a device and not the simulator. I replicated the same error message when I try to run your code or code I have that uses AVSpeachUtterance in the simulator. Not sure if this is a bug or just a limitation of the simulator. To get things working, try commenting out the line:

utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-au"];

Does it work then? Without this line of code things working as they should for me on an iPhone 5 (8.0.2), however if I use any of the codes language codes shown here (What are the BCP-47 voice codes available for iOS 7 AVSpeechSynthesisVoice?), no text is spoken. The only way I can get things to work when I explicitly set the language is if I use @"en-GB", which is also the language the phone is configured for in settings. I can use another language code if I change the language of my phone in settings, say to US english and @"en-US".

As an FYI, the bug that required an initial bit of dummy text, i.e. @" " to get things working seems to be fixed in 8.0.2