自学内容网 自学内容网

python文字转wav音频

借鉴博客

一.前期准备

1. pip install baidu-aip
2. pip install pydub
3. 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")

三.最终结果


原文地址:https://blog.csdn.net/m0_51650696/article/details/142384159

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!