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)