iOS7 文本转语音 AVSpeechSynthesizer

http://www.cnblogs.com/qingjoin/archive/2013/06/28/3160945.html

OS7 的这个功能确实不错。我刚试了下,用官方提供的API ,简单的几句代码就能实现文本转语音!

Xcode 5.0 

工程建好后首先把AVFoundation.framework 加入到工程

 

 AVSpeechSynthesizer *av = [[AVSpeechSynthesizer alloc]init];
    AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:@"Hello qingjoin"]; //需要转换的文本
    [av speakUtterance:utterance];
//以上三行代码就可以搞定文本转语音   有API就是省事。哈哈

 

 

复制代码
/*******************************************************/
//具体可参考以下demo   记得.h文件里别忘记了这个哦
#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];  //需要转换的文本
    [av speakUtterance:utterance];
}

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

@end
复制代码

2013-06-28 14:54:07.817 AVideoSpeechDemo[5468:60b] Enqueue: <AXSpeechAction: 0x166d9820> hello :Pitch 1.000000 : Language: (null)

2013-06-28 14:54:22.791 AVideoSpeechDemo[5468:60b] Enqueue: <AXSpeechAction: 0x166f94f0> hello, qingjoin :Pitch 1.000000 : Language: (null)

2013-06-28 15:06:42.424 AVideoSpeechDemo[5468:60b] Enqueue: <AXSpeechAction: 0x166f3af0> 你好,我是qingjoin ! hello :Pitch 1.000000 : Language: (null)





demo 下载连接:http://files.cnblogs.com/qingjoin/AVideoSpeechDemo.zip

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值