iOS develops TTS technology that is text to voice

Source: Internet
Author: User
Tags instance method
iOS develops TTS technology that is text to voice implementation of text-to-speech for iOS system

Before iOS7, it may be necessary for a third-party repository to implement voice broadcast text content. Now after iOS, the system provides us with the function of voice broadcast text, we can not only broadcast English content, can also broadcast the implementation of Chinese characters.
Tts[text to Speech]:
Rely primarily on avspeechsynthesizer,avspeechutterance,avspeechsynthesisvoice, and to use these classes you must first join the Avfoundation framework:
Avspeechsynthesisvoice: Used to configure pronunciation, support pronunciation is very much;
The [Avspeechsynthesisvoicespeechvoices] class method can be used to see the type of pronunciation supported;
Avspeechutterance: This class is used to make the string synthesis for the speech object to provide to the avspeechsynthesizer to play, this class also has some instance method to control the speed, the tone and so on.

Implementation code: The system implementation method is relatively simple, but need to be above iOS7, IOS7 before the general speech recognition is relying on some third-party libraries, or using Google Voice interface (described below)
Create a TextField, enter the text that will be played, create a button, and implement the text-to-speech

Self.textfield = [[Uitextfield alloc] Initwithframe:cgrectmake (M, M,)];
[Self.view AddSubview:self.textField]; Self.textField.borderStyle = 3;
Self.textField.placeholder = @ "Please enter text";

Self.button = [UIButton Buttonwithtype:uibuttontypesystem];
[Self.view AddSubview:self.button];
Self.button.frame = CGRectMake (M, 180, MB);
[Self.button settitle:@ "Voice playback" forstate:uicontrolstatenormal];
[Self.button addtarget:self Action: @selector (playstring:) forcontrolevents:uicontroleventtouchupinside];

Text To Speech method implementation code:

-(void) playstring: (UIButton *) button
{
    if (![ Self.textField.text isequaltostring:@ ""]) {
        avspeechutterance *utterance = [avspeechutterance SpeechUtteranceWithString:self.textField.text];
        Avspeechsynthesisvoice *voice = [avspeechsynthesisvoice voicewithlanguage:@ ' ZH-CN '];//set language
        Utterance.voice = Voice;
        NSLog (@ "%@", [Avspeechsynthesisvoice speechvoices]);
        Utterance.volume= 1;  Set Volume (0.0~1.0) defaults to 1.0
        utterance.rate= 0.01;  Set speed
        utterance.pitchmultiplier= 1.1;  Set intonation
        Avspeechsynthesizer *synth = [[Avspeechsynthesizer alloc]init];
        [Synth speakutterance:utterance];

    }

As far as I'm testing, iOS provides an interface that is more blunt and does not pause

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.