一.前期准备
-
pip install baidu-aip
-
pip install pydub
-
sudo apt-get install ffmpeg
二.代码
from aip import AipSpeech
from pydub import AudioSegment
import time
#input your own APP_ID/API_KEY/SECRET_KEY
APP_ID = '14891501'
API_KEY = 'EIm2iXtvDSplvR5cyHU8dAeM'
SECRET_KEY = '4KkGGzTq2GVrBEYPLXXWEEIoyLL1F6Zt '
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis('激光开始扫描中,请勿直视', 'zh', 1, { 'vol': 4,'per':4 })
if not isinstance(result, dict):
with open('test.mp3', 'wb') as f:
f.write(result)
# Step 2, convert the mp3 file to wav file
sound = AudioSegment.from_mp3('test.mp3')
sound.export("test.wav", format="wav")