IOS implements TTS (text-to-speech) __ios

Source: Internet
Author: User

Objective


Before IOS7, general speech recognition is relying on some third-party libraries, or using Google Voice interface, where Google's voice interface is best.

The great Google ~ ~ but now upgraded iOS with text to voice is also very good, support a lot of text, but the sound is a bit harsh:

The implementation of IOS 7 text-turn speech

Implementing TTS relies primarily on avspeechsynthesizer,avspeechutterance,avspeechsynthesisvoice, which must first be joined

Avfoundation Framework:

Avspeechsynthesisvoice: Used to configure pronunciation and to support a lot of pronunciation. Personal feeling Taiwan sounds best to listen ~ by calling

The [Avspeechsynthesisvoicespeechvoices] class method can be used to see the type of pronunciation supported;

Avspeechutterance: This class is used to make the string composition for the speech object provided to the Avspeechsynthesizer to play, this class also has some

Instance methods are used to control speed, tone, and so on.

Implementation code:

Avspeechutterance *utterance = [avspeechutterancespeechutterancewithstring:@ "Hello"];

English pronunciation

Avspeechsynthesisvoice *voice = [avspeechsynthesisvoicevoicewithlanguage:@ "EN-GB"];

Utterance.voice = Voice;

NSLog (@ "%@", [avspeechsynthesisvoicespeechvoices]);

Avspeechsynthesizer *synth = [[Avspeechsynthesizeralloc]init];

[Synth speakutterance:utterance];

Using the SDK's own method to implement TTS is very simple, but only IOS7 to support these methods, all still need to find a workaround;


Using the Google interface to implement TTS

The common way to use Google interface to text-to-speech text is to upload a text to Google's interface, and then return it to a MP3-formatted audio. Download down to play. This method is rather troublesome.

I found a way to be lazy when I used the webview. There is a property in the webview that can play the streaming media on the page automatically, as long as you set this property and you don't have to download it straight

The audio is then played.

Implementation code

NSString *str = [nsstringstringwithformat:@ "http://translate.google.com/translate_tts?tl=en&q=%@", @ "Hello"];

Nsurl *url = [NSURLURLWITHSTRING:STR];

Nsurlrequest *request = [[Nsurlrequestalloc]initwithurl:url];

UIWebView *webview = [[Uiwebviewalloc]init];

Webview.allowsinlinemediaplayback = yes;//Set this property WebView will automatically broadcast streaming media on the Web page, the ipad is the default yes;

IPhone Safari defaults to NO. IPad Safari defaults to YES

Now just load this page and the text you choose will be played when the load is complete.

[Self.webViewloadRequest:request];


PS: Next I will write some speech recognition on the iOS content, in iOS recorded in the PCM format of the recording into the FLAC format, and then upload to Google Interface for speech recognition, interested in continued attention ~ ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.