如何以编程方式使用 iOS 语音合成器?(文字转语音) [英] How to programmatically use iOS voice synthesizers? (text to speech)

查看:32
本文介绍了如何以编程方式使用 iOS 语音合成器?(文字转语音)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 设备为辅助功能的 VoiceOver 功能嵌入了语音合成器.有没有办法以编程方式使用这些合成器来生成基于文本的声音?

iOS devices have embedded voice synthesizers for Accessibility's VoiceOver feature. Is there a way you can use these synthesizers programmatically to generate text-based sounds?

我的问题是:我正在开发一个简单的应用程序,让孩子们学习颜色,而不是用我想要支持的每种语言记录颜色的名称并将它们存储为音频文件,我宁愿生成声音在运行时使用一些文本转语音功能.

My problem is: I'm working on a simple app for kids to learn colors and rather than recording the names of the colors in each language i want to support and storing them as audio files, i'd rather generate the sounds at runtime with some text-to-speech feature.

谢谢

推荐答案

从 iOS 7 开始,Apple 提供了 这个 API.

Starting from iOS 7, Apple provides this API.

参见这个答案.

目标 C

#import <AVFoundation/AVFoundation.h>
…
AVSpeechUtterance *utterance = [AVSpeechUtterance 
                            speechUtteranceWithString:@"Hello World!"];
AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
[synth speakUtterance:utterance];

迅捷

import AVFoundation
…
let utterance = AVSpeechUtterance(string: "Hello World!")
let synth = AVSpeechSynthesizer()
synth.speakUtterance(utterance)

这篇关于如何以编程方式使用 iOS 语音合成器?(文字转语音)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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