Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active July 22, 2016 22:40
Show Gist options
  • Save Koze/d9d6655d3a6d09259ba2 to your computer and use it in GitHub Desktop.
Save Koze/d9d6655d3a6d09259ba2 to your computer and use it in GitHub Desktop.
Text Speech Example in iOS 8
// iOS 8 example
- (void)speechText:(NSString *)text
{
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
utterance.rate = AVSpeechUtteranceMinimumSpeechRate;
utterance.volume = 1;
// initialize voice with language code
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:[AVSpeechSynthesisVoice currentLanguageCode]];
utterance.voice = voice;
[synthesizer speakUtterance:utterance];
}
// iOS 9 example
- (void)speechText:(NSString *)text
{
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
utterance.rate = AVSpeechUtteranceMinimumSpeechRate;
utterance.volume = 1;
// initialize voice with voice identifier
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex];
utterance.voice = voice;
[synthesizer speakUtterance:utterance];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment