IOS7 Text to Speech AVSpeechSynthesizer

Source: Internet
Author: User

This feature of OS7 is really good. I just tried to use the official API to convert Text to Speech with just a few simple codes!

Xcode 5.0

After the project is created, add the AVFoundation. framework to the project.

 

 

AVSpeechSynthesizer * av = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc] initWithString: @ "Hello qingjoin"]; // The text to be converted
[Av speakUtterance: utterance];
// The above three lines of code can be used to handle text-to-speech conversion with APIs, which saves trouble. Haha
 

 


/*************************************** ****************/
// For details, refer to the following demo. Remember this in the H file.
# Import <AVFoundation/AVSpeechSynthesis. h>

//
// ViewController. m
// AVideoSpeechDemo
//
// Created by qingyun on 6/28/13.
// Copyright (c) 2013 qingyun. All rights reserved.
//
# Import "ViewController. h"

@ Interface ViewController ()

@ End

@ Implementation ViewController

-(Void) viewDidLoad
{
[Super viewDidLoad];
_ TextS. delegate = self;
// Do any additional setup after loading the view, typically from a nib.
}

-(Void) didReceiveMemoryWarning
{
[Super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(IBAction) textToSpeechBtnPress :( id) sender
{
AVSpeechSynthesizer * av = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc] initWithString: _ textS. text]; // The text to be converted
[Av speakUtterance: utterance];
}

-(BOOL) textFieldShouldReturn :( UITextField *) textField
{
[TextField resignFirstResponder];
Return YES;
}

@ End
14:54:07. 817 AVideoSpeechDemo [5468: 60b] Enqueue: <AXSpeechAction: 0x166d9820> hello: Pitch 1.000000: Language: (null)

14:54:22. 791 AVideoSpeechDemo [5468: 60b] Enqueue: <AXSpeechAction: 0x166f94f0> hello, qingjoin: Pitch 1.000000: Language: (null)

15:06:42. 424 AVideoSpeechDemo [5468: 60b] Enqueue: <AXSpeechAction: 0x166f3af0> Hello, I am qingjoin! Hello: Pitch 1.000000: Language: (null)

 

 

 

 

 

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.