ios - iOS 中的中文文本转语音

标签 ios text-to-speech

有谁知道如何在 iOS 中实现中文文字转语音?

任何链接或建议都会有所帮助。

最佳答案

正如 Sten 所说,您可以使用 iSpeech .这是相同的答案,更详细:

您可以使用他们的 API ,但问题是它每天只能使用 200 次。

如果你想无限使用,你需要购买它。解决这个问题的一种方法是访问他们的 demo program 返回的数据。 (以 mp3 格式返回)。

我用 Python 编写了一小段代码来演示这一点。 Python 可用于 iOS,来自 this地点。演示程序一次限制 20 个单词,因此您的程序必须每 20 个单词拆分一次,并分别输入这些片段。以下代码不使用缓冲区,因此段之间可能会有轻微的延迟。

from urllib import quote_plus

def speak(text): 
    import pydshow 
    words = text.split() 
    temp = [] 
    stuff = [] 
    while words: 
        temp.append(words.pop(0)) 
        if len(temp) == 24: 
            stuff.append(' '.join(temp)) 
            temp = [] 
    stuff.append(' '.join(temp)) 
    for i in stuff: 
        pydshow.PlayFileWait('http://api.ispeech.org/api/rest?apikey=8d1e2e5d3909929860aede288d6b974e&format=mp3&action=convert&voice=chchinesemale&text='+quote_plus(i))

if __name__ == '__main__':
       speak('Hello. This is a text-to speech test.')

我觉得这很理想,因为演示程序确实使用了 API,但它使用了用于演示程序的 API key 。因此,它永远不会用完。 key 是 8d1e2e5d3909929860aede288d6b974e。此外,该程序非常简单,可以适用于任何编程语言。

您可以在没有程序的情况下实际测试它,方法是在您的地址栏中输入以下内容:

http://api.ispeech.org/api/rest?apikey=8d1e2e5d3909929860aede288d6b974e&format=mp3&action=convert&voice=chchinesemale&text=Hello

您可以按照自己的需要定制:

http://api.ispeech.org/api/rest?apikey=8d1e2e5d3909929860aede288d6b974e&format=mp3&action=convert&voice=chchinesemale&text=

后跟您想说的文字。您还可以调整性别,方法是在本例中将 chchinesemale 更改为 iSpeech 提供的其他内容。例如,chinesefemale。这将说出相同的文本,但会用女性的声音。可以找到有关代码的规范 here .

希望我有所帮助!

注意:Pydshow 是我对 DirectShow 的包装,它仅适用于 Windows。如果您选择此方法,则必须为 iOS 找到替代方法。

关于ios - iOS 中的中文文本转语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10413157/

相关文章:

ios - TableView 数据未显示在 iOS6 和 Xcode 的新 Storyboard场景中

ios - 开发者证书不再有效,但应用已获得 Apple 批准

java - Android TTS如何在textview中显示说话的单词

ios - 在 Text to Speech 运行时突出显示文本

android - 自动来电/来电拦截

ios - 如何在 swift 中初始化 Custom UITableViewCell 的不同属性

ios - 不使用约束的 UIToolbar 的 safeAreaInsets

ios - swift : UITableViewCell size to width of parent UITableView with autolayout enabled

swift - 为什么 NSSpeechSynthesizer 不调用它的委托(delegate)方法?

java - Text to Speech 获取系统默认音调和语速