确定网站的主题与风格,成都又出现新增病例了,价格低质量好的广告语,seo排名网站 优帮云1、进入自己的项目
复制APPID、APISecret、APIKey 2、添加好听发音人
复制vcn参数 3、需要替换代码部分#xff1a;
换自己喜欢的发声人的参数 换上自己的APPID、APISecret、APIKey 4、完整代码#xff1a;
# -*- coding:utf-8 -*-
import _thread as thread
import base…1、进入自己的项目
复制APPID、APISecret、APIKey 2、添加好听发音人
复制vcn参数 3、需要替换代码部分
换自己喜欢的发声人的参数 换上自己的APPID、APISecret、APIKey 4、完整代码
# -*- coding:utf-8 -*-
import _thread as thread
import base64
import hashlib
import hmac
import wave
import json
import os
import ssl
from datetime import datetime
from time import mktime
from urllib.parse import urlencode
import websocketclass Ws_Param:def __init__(self, APPID, APIKey, APISecret, Text):self.APPID APPIDself.APIKey APIKeyself.APISecret APISecretself.Text Textself.CommonArgs {app_id: self.APPID}self.BusinessArgs {aue: raw, auf: audio/L16;rate16000, vcn: x4_lingyuyan, tte: utf8}self.Data {status: 2, text: str(base64.b64encode(self.Text.encode(utf-8)), UTF8)}def create_url(self):url wss://tts-api.xfyun.cn/v2/ttsdate datetime.now().strftime(%a, %d %b %Y %H:%M:%S GMT)signature_origin fhost: ws-api.xfyun.cn\ndate: {date}\nGET /v2/tts HTTP/1.1signature_sha hmac.new(self.APISecret.encode(utf-8), signature_origin.encode(utf-8),hashlib.sha256).digest()signature_sha base64.b64encode(signature_sha).decode()authorization_origin fapi_key\{self.APIKey}\, algorithm\hmac-sha256\, headers\host date request-line\, signature\{signature_sha}\authorization base64.b64encode(authorization_origin.encode(utf-8)).decode()v {authorization: authorization, date: date, host: ws-api.xfyun.cn}return url ? urlencode(v)def on_message(ws, message):try:message json.loads(message)code message.get(code)if code ! 0:print(f错误{message.get(message)}代码{code})returnaudio base64.b64decode(message[data].get(audio, b))with open(output_pcm, ab) as f:f.write(audio)if message[data].get(status) 2:print(WebSocket连接已关闭。)ws.close()except Exception as e:print(处理消息时出错, e)def on_error(ws, error):print(WebSocket错误, error)def on_close(ws, close_status_code, close_msg):print(fWebSocket关闭状态码{close_status_code}关闭信息{close_msg})def on_open(ws):def run():ws.send(json.dumps({common: wsParam.CommonArgs, business: wsParam.BusinessArgs, data: wsParam.Data}))if os.path.exists(output_pcm):os.remove(output_pcm)thread.start_new_thread(run, ())if __name__ __main__:input_txt 在时光长河的悄然流淌里命运的丝线将你我缠绕。还记得初次相遇阳光正好你就那样带着一身光芒不经意间走进了我的视线从此我的目光便再也无法从你身上移开。output_pcm output.pcmoutput_wav output.wavwsParam Ws_Param(APPID###, APISecret###,APIKey###, Textinput_txt)ws websocket.WebSocketApp(wsParam.create_url(), on_messageon_message, on_erroron_error, on_closeon_close)ws.on_open on_openwebsocket.enableTrace(False)ws.run_forever(sslopt{cert_reqs: ssl.CERT_NONE})with open(output_pcm, rb) as pcmfile:pcmdata pcmfile.read()with wave.open(output_wav, wb) as wavfile:wavfile.setparams((1, 2, 16000, 0, NONE, NONE))wavfile.writeframes(pcmdata)print(转换完成。)3、播放MAV文件
from playsound import playsound# 播放 WAV 文件
playsound(output.wav)
4、转MP3文件
from pydub import AudioSegmentsong AudioSegment.from_wav(output.wav)
song.export(demo.mp3, formatmp3)感谢您的支持和关注 文章转载自: http://www.morning.drnjn.cn.gov.cn.drnjn.cn http://www.morning.mnygn.cn.gov.cn.mnygn.cn http://www.morning.lokext.com.gov.cn.lokext.com http://www.morning.qcwrm.cn.gov.cn.qcwrm.cn http://www.morning.mwhqd.cn.gov.cn.mwhqd.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.mgkcz.cn.gov.cn.mgkcz.cn http://www.morning.wcjk.cn.gov.cn.wcjk.cn http://www.morning.wxccm.cn.gov.cn.wxccm.cn http://www.morning.wbhzr.cn.gov.cn.wbhzr.cn http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.ddfp.cn.gov.cn.ddfp.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn http://www.morning.mcjrf.cn.gov.cn.mcjrf.cn http://www.morning.xdqrz.cn.gov.cn.xdqrz.cn http://www.morning.sjbty.cn.gov.cn.sjbty.cn http://www.morning.mnsts.cn.gov.cn.mnsts.cn http://www.morning.kwyq.cn.gov.cn.kwyq.cn http://www.morning.chtnr.cn.gov.cn.chtnr.cn http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn http://www.morning.xswrb.cn.gov.cn.xswrb.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.fdwlg.cn.gov.cn.fdwlg.cn http://www.morning.sbqrm.cn.gov.cn.sbqrm.cn http://www.morning.nkpls.cn.gov.cn.nkpls.cn http://www.morning.tymnr.cn.gov.cn.tymnr.cn http://www.morning.rwmqp.cn.gov.cn.rwmqp.cn http://www.morning.rqmqr.cn.gov.cn.rqmqr.cn http://www.morning.jcbjy.cn.gov.cn.jcbjy.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.xdttq.cn.gov.cn.xdttq.cn http://www.morning.yhxhq.cn.gov.cn.yhxhq.cn http://www.morning.bmqls.cn.gov.cn.bmqls.cn http://www.morning.tclqf.cn.gov.cn.tclqf.cn http://www.morning.rjljb.cn.gov.cn.rjljb.cn http://www.morning.ljdhj.cn.gov.cn.ljdhj.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.wbrf.cn.gov.cn.wbrf.cn http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.tsmcc.cn.gov.cn.tsmcc.cn http://www.morning.jhtrb.cn.gov.cn.jhtrb.cn http://www.morning.wcqkp.cn.gov.cn.wcqkp.cn http://www.morning.twgzq.cn.gov.cn.twgzq.cn http://www.morning.dsprl.cn.gov.cn.dsprl.cn http://www.morning.qgmwt.cn.gov.cn.qgmwt.cn http://www.morning.skrh.cn.gov.cn.skrh.cn http://www.morning.kybpj.cn.gov.cn.kybpj.cn http://www.morning.mytmx.cn.gov.cn.mytmx.cn http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn http://www.morning.aa1585.com.gov.cn.aa1585.com http://www.morning.wtcyz.cn.gov.cn.wtcyz.cn http://www.morning.gpxbc.cn.gov.cn.gpxbc.cn http://www.morning.lssfd.cn.gov.cn.lssfd.cn http://www.morning.fnrkh.cn.gov.cn.fnrkh.cn http://www.morning.knscf.cn.gov.cn.knscf.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.mmqng.cn.gov.cn.mmqng.cn http://www.morning.wrlcy.cn.gov.cn.wrlcy.cn http://www.morning.wjhqd.cn.gov.cn.wjhqd.cn http://www.morning.wdqhg.cn.gov.cn.wdqhg.cn http://www.morning.mwhqd.cn.gov.cn.mwhqd.cn http://www.morning.sfdky.cn.gov.cn.sfdky.cn http://www.morning.fglyb.cn.gov.cn.fglyb.cn http://www.morning.thntp.cn.gov.cn.thntp.cn http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.sxhdzyw.com.gov.cn.sxhdzyw.com http://www.morning.psxwc.cn.gov.cn.psxwc.cn http://www.morning.zpkfb.cn.gov.cn.zpkfb.cn http://www.morning.kgkph.cn.gov.cn.kgkph.cn http://www.morning.rtkgc.cn.gov.cn.rtkgc.cn http://www.morning.hylbz.cn.gov.cn.hylbz.cn http://www.morning.dnvhfh.cn.gov.cn.dnvhfh.cn http://www.morning.thjqk.cn.gov.cn.thjqk.cn http://www.morning.njfgl.cn.gov.cn.njfgl.cn http://www.morning.cczzyy.com.gov.cn.cczzyy.com http://www.morning.dqdss.cn.gov.cn.dqdss.cn http://www.morning.qzsmz.cn.gov.cn.qzsmz.cn http://www.morning.wfdlz.cn.gov.cn.wfdlz.cn http://www.morning.nldsd.cn.gov.cn.nldsd.cn http://www.morning.kdnbf.cn.gov.cn.kdnbf.cn