Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically use iOS voice synthesizers? (text to speech)

iOS devices have embedded voice synthesizers for Accessibility's VoiceOver feature. Is there a way you can use these synthesizers programmatically to generate text-based sounds?

My problem is: I'm working on a simple app for kids to learn colors and rather than recording the names of the colors in each language i want to support and storing them as audio files, i'd rather generate the sounds at runtime with some text-to-speech feature.

Thanks

[EDIT: this question was asked pre-iOS7 so you should really consider the voted answer and ignore older ones, unless you're a software archeologist]

like image 215
Dirty Henry Avatar asked Mar 30 '12 08:03

Dirty Henry


People also ask

How do I use text to speech on IOS?

Go to Settings > Accessibility > Spoken Content. Adjust any of the following: Speak Selection: To hear text you selected, tap the Speak button. Speak Screen: To hear the entire screen, swipe down with two fingers from the top of the screen.

How do I get more Voices for text to speech for iPhone?

Go to Settings > Accessibility and tap Spoken Content. Turn on Speak Selection or Speak Screen, or both. Select Voices. Choose the voice and dialect that you want Speak Screen and Speak Selection to use.

How do I convert speech to text in IOS Swift?

Integrate speech recognition swift , create a new state object named speechRecognizer . The initializer requests access to the speech recognizer and microphone the first time the system calls the object. You'll begin transcribing when the meeting view appears and stop recording when the meeting view disappears.


2 Answers

Starting from iOS 7, Apple provides this API.

See this answer.

Objective-C

#import <AVFoundation/AVFoundation.h> … AVSpeechUtterance *utterance = [AVSpeechUtterance                              speechUtteranceWithString:@"Hello World!"]; AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init]; [synth speakUtterance:utterance]; 

Swift

import AVFoundation … let utterance = AVSpeechUtterance(string: "Hello World!") let synth = AVSpeechSynthesizer() synth.speakUtterance(utterance) 
like image 193
Onato Avatar answered Sep 20 '22 02:09

Onato


#import <AVFoundation/AVFoundation.h>  AVSpeechSynthesizer *av = [[AVSpeechSynthesizer alloc] init]; AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:@"Text to say"];  [av speakUtterance:utterance]; 
like image 34
user2518512 Avatar answered Sep 20 '22 02:09

user2518512