iOS speech synthesis

Source: Internet
Author: User

In IOS7, Apple has introduced TTS technology that enables speech synthesis without the need for a network environment.

The main APIs for iOS7 speech synthesis are as follows:

1, Avspeechutterance, is the basic unit of speech synthesis, which encapsulates some parameters that affect the need for speech synthesis: voice, intonation, speed, and delay.

2, Avspeechsynthesisvoice, is the voice object in speech synthesis, it mainly includes voice and region two aspects.

3, Avspeechsynthesizer, voice synthesizer management class, through the Speakutterance: Method Management Avspeechsynthesizer.

4, Avspeechsynthesizerdelegate, is the avspeechsynthesizer of the Commission agreement.

The code is as follows:

#import "DemoVC36.h"

#import

@interface DemoVC36 () @property (weak, nonatomic) Iboutlet Uitextview *textview;

@property (Weak, nonatomic) Iboutlet UISlider *slider;

@property (nonatomic, strong) Avspeechsynthesizer *speechsynthesizer;

@end

@implementation DemoVC36

-(void) Viewdidload {

[Super Viewdidload];

To TextView

[Self.textView.layer setborderwidth:0.5f];

[Self.textView.layer Setbordercolor:[uicolor Graycolor]. Cgcolor];

[Self.textview setdelegate:self];

Self.speechsynthesizer = [[Avspeechsynthesizer alloc] init];

Self.speechSynthesizer.delegate = self;

}

-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text{

BOOL retval = TRUE;

if ([text isequaltostring:@ "\ n"]) {

[Self.textview Resignfirstresponder];

retval = FALSE;

}

return retval;

}

-(Ibaction) speakbuttonwaspressed: (UIButton *) Sender {

NSString *str = @ "Wei Fang is a handsome man";

Avspeechutterance *utt = [Avspeechutterance speechutterancewithstring:str];

Utt.rate = [Self.slider value];

[Self.speechsynthesizer Speakutterance:utt];

}

-(Ibaction) Speechspeedshouldchange: (ID) Sender {

UISlider *slider = (UISlider *) sender;

Nsinteger val = round (slider.value);

NSLog (@ "%@", [NSString stringwithformat:@ "%ld", Val]);

}

#pragma mark--avspeechsynthesizerdelegate

-(void) SpeechSynthesizer: (Avspeechsynthesizer *) synthesizer didstartspeechutterance: (Avspeechutterance *) utterance{

NSLog (@ "speech synthesis start");

}

-(void) SpeechSynthesizer: (Avspeechsynthesizer *) synthesizer didfinishspeechutterance: (Avspeechutterance *) utterance{

NSLog (@ "speech synthesis complete");

}

@end

iOS speech synthesis

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.