python文字转语音库及使用方法

2023-05-13,,

作者:陈哲
链接:https://www.zhihu.com/question/473797102/answer/2019063801
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Python 文字语音(TTS,TextToSpeech)有很多库可以实现,例如:

pyttsx3
gTTS
IBM Watson TTS
win32com(Windows 平台)

注意:如未安装请先安装,为节省时间,以下我把安装和使用写在一个代码块中了,应该是分开的。

pyttsx3

pip install pyttsx3

import pyttsx3
pyttsx3.speak("Hello World")

gTTS

pip install gTTS

from gtts import gTTS

tts = gTTS('Hello World')
tts.save('hello.mp3')

IBM Watson TTS

pip install tts-watson

from tts_watson.TtsWatson import TtsWatson

ttsWatson = TtsWatson('watson_user', 'watson_password', 'en-US_AllisonVoice')
ttsWatson.play("Hello World")

win32com(Windows 平台)

import win32com.client as wincl

speak = wincl.Dispatch("SAPI.SpVoice")
speak.Speak("Hello World")


当然,还包括国内的语音平台也提供 TTS 服务,例如,讯飞科技,百度智能语音开放平台,阿里云,腾讯云,思必驰,捷通华声(灵云)等等。

在这里没有直接给出结论,到底是哪个好呢?如果脱离了业务,就会变得毫无意义,不然也就没有类似于“技术选型”的必要性了,以上,只是提供了最初最初的参考。

python文字转语音库及使用方法的相关教程结束。

《python文字转语音库及使用方法.doc》

下载本文的Word格式文档,以方便收藏与打印。