Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Text To Speech Api

I can't seem to find anything on this. Are there any Siri classes or API's in iOS7 that let you do text to speech? All I am trying to do is something like the following:

[siriInstance say:@"This is a test"]; 

And then have Siri say it from my app.

It seems we should be capable of doing this, no? Seems like a trivial thing.

like image 788
Jesse Avatar asked Mar 21 '14 14:03

Jesse


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.

What is Avaudioengine?

An object that manages a graph of audio nodes, controls playback, and configures real-time rendering constraints.

What is AVFoundation Swift?

AVFoundation is a multimedia framework with APIs in Objective-C and Swift, which provides high-level services for working with time-based audiovisual media on Apple Darwin-based operating systems: iOS, macOS, tvOS, and watchOS. It was first introduced in iOS 4 and has seen significant changes in iOS 5 and iOS 6.


1 Answers

Since iOS 7 you have a new TTS Api.

In Objective C

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init]; AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Some text"]; [utterance setRate:0.2f]; [synthesizer speakUtterance:utterance]; 

In Swift

let synthesizer = AVSpeechSynthesizer() let utterance = AVSpeechUtterance(string: "Some text") utterance.rate = 0.2 

You can also change the voice like this :

utterance.voice = AVSpeechSynthesisVoice(language: "fr-FR") 

And then speek

  • In Swift 2 synthesizer.speakUtterance(utterance)

  • In Swift 3 synthesizer.speak(utterance)

Don't forget to import AVFoundation

Helpful methods

You can Stop or Pause all speech using these two methods :

- (BOOL)pauseSpeakingAtBoundary:(AVSpeechBoundary)boundary; - (BOOL)stopSpeakingAtBoundary:(AVSpeechBoundary)boundary; 

The AVSpeechBoundary indicates if the speech should pause or stop immediately (AVSpeechBoundaryImmediate) or it should pause or stop after the word currently being spoken (AVSpeechBoundaryWord).

Check the AVSpeechSynthesizer Doc

like image 88
Ali Abbas Avatar answered Sep 19 '22 23:09

Ali Abbas