How to convert String to Audio (Sound) file in ios

2020-07-28 11:38发布

问题:

Is there any way to convert string (character) to Audio file in iOS? My question is I have a string and that string I want to convert into sound file, Is it possible without using any third party api?

Thanks in Advance.....

回答1:

AVSpeechSynthesizer Tutorial – Letting Your App Speak Like Siri

avspeechsynthesizer-ios-text-speech-ios-7

but this is only available iOS 7

sample app



回答2:

Yes, with iOS 7, The AVSpeechSynthesizer class produces synthesized speech from text on an iOS device, and provides methods for controlling or monitoring the progress of ongoing speech.

EDIT: Simply add AVFoundation framework in your project, Add the import statement #import <AVFoundation/AVFoundation.h> and execute this piece of code:

AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Really, its very easy."];
[utterance setRate:0.5f];
[speechSynthesizer speakUtterance:utterance];


回答3:

In the previous version of IOS 7 use flute library http://artofsystems.blogspot.in/2009/02/speech-synthesis-on-iphone-with-flite.html

For IOS 7 there is inbuilt feature for Text to speech conversion avspeechsynthesizer-ios-text-speech-ios-7