Files
jupyter/语音合成.ipynb
2021-11-12 00:14:23 +08:00

3.3 KiB

In [ ]:
#gTTS语音
from gtts import gTTS
#engine = pyttsx3.init('espeak')
tts = gTTS(text="军士上前,将英玉兰架起,英玉兰被举下",lang='zh-cn')
#engine.save_to_file("欢迎使用百度语音合成,本次测试为Python接口",'./test')
tts.save("./test.mp3")
print('ok')
In [1]:
#百度语音在线
from aip import AipSpeech

""" 你的 APPID AK SK """
APP_ID = '17553946'
API_KEY = 'i5LBXalkBn2KHTqdifesA1EB'
SECRET_KEY = '1ktP6qDH7nMFHjotRdKpnI13w41Bvk59'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

result  = client.synthesis('军士上前,将英玉兰架起,英玉兰被举下。', 'zh', 5, {
    'vol': 5,'per': 4,
})

# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
    with open('./test3.mp3', 'wb') as f:
        f.write(result)
else:print(result)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-3dd6f47059b1> in <module>
      1 #百度语音在线
----> 2 from aip import AipSpeech
      3 
      4 """ 你的 APPID AK SK """
      5 APP_ID = '17553946'

ModuleNotFoundError: No module named 'aip'
In [ ]: