iOS文字转语音Api [英] iOS Text To Speech Api

查看:753
本文介绍了iOS文字转语音Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到任何相关信息。在iOS7中是否有任何Siri类或API可以让您进行文本到语音转换?我想做的就是以下内容:

I can't seem to find anything on this. Are there any Siri classes or API's in iOS7 that let you do text to speech? All I am trying to do is something like the following:

[siriInstance say:@"This is a test"];

然后让Siri从我的应用程序中说出来。

And then have Siri say it from my app.

看来我们应该有能力这样做,不是吗?看似简单的事情。

It seems we should be capable of doing this, no? Seems like a trivial thing.

推荐答案

从iOS 7开始,你有一个新的TTS Api。

Since iOS 7 you have a new TTS Api.

目标C

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Some text"];
[utterance setRate:0.2f];
[synthesizer speakUtterance:utterance];

在Swift中

let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "Some text")
utterance.rate = 0.2

你也可以改变这样的声音:

You can also change the voice like this :

utterance.voice = AVSpeechSynthesisVoice(language: "fr-FR")

然后speek


  • 在Swift 2中
    synthesizer.speakUtterance(话语)

在Swift 3中
synthesizer.speak (话语)

不要忘记导入AVFoundation

有用的方法

您可以停止或使用以下两种方法暂停所有语音:

You can Stop or Pause all speech using these two methods :

- (BOOL)pauseSpeakingAtBoundary:(AVSpeechBoundary)boundary;
- (BOOL)stopSpeakingAtBoundary:(AVSpeechBoundary)boundary;

AVSpeechBoundary 表示演讲是否应暂停或立即停止( AVSpeechBoundaryImmediate ),或者在当前正在说出的单词后停止或停止( AVSpeechBoundaryWord )。

The AVSpeechBoundary indicates if the speech should pause or stop immediately (AVSpeechBoundaryImmediate) or it should pause or stop after the word currently being spoken (AVSpeechBoundaryWord).

检查 AVSpeechSynthesizer Doc

这篇关于iOS文字转语音Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆