当前位置: 首页 > news >正文

苏州营销网站建设惠州seo排名

苏州营销网站建设,惠州seo排名,免费网上开店,郑州水晶奖杯制作1、进入自己的项目 复制APPID、APISecret、APIKey 2、添加好听发音人 复制vcn参数 3、需要替换代码部分: 换自己喜欢的发声人的参数 换上自己的APPID、APISecret、APIKey 4、完整代码: # -*- 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;rate=16000", "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/tts'date = datetime.now().strftime("%a, %d %b %Y %H:%M:%S GMT")signature_origin = f"host: ws-api.xfyun.cn\ndate: {date}\nGET /v2/tts HTTP/1.1"signature_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 = f"api_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(f"WebSocket关闭,状态码:{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.pcm"output_wav = "output.wav"wsParam = Ws_Param(APPID='###', APISecret='###',APIKey='###', Text=input_txt)ws = websocket.WebSocketApp(wsParam.create_url(), on_message=on_message, on_error=on_error, on_close=on_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", format="mp3")

感谢您的支持和关注!!!

http://www.dt0577.cn/news/29553.html

相关文章:

  • 成都电子商务网站建设公司广告推广免费发布
  • 永川疫情风险区新乡百度网站优化排名
  • 新乡网站建设多少钱全网营销推广靠谱吗
  • 国际商业网站百度新闻首页头条
  • 贵州建网站高端定制网站建设公司
  • wordpress 管理界面百度移动端关键词优化
  • 美国有哪些做促销的网站百姓网
  • 成都网站建设免费培训网站
  • 电子商务网站建设与管理李建忠网络推广培训
  • 网站设计标杆企业百度贴吧免费发布信息
  • 巴中公司网站建设个人网站设计内容
  • 如何做网站规划最新天气预报最新消息
  • 泰安可以做网站的公司seo关键词推广渠道
  • 学校建设网站的结论关键词优化公司如何选择
  • 工程公司资质办理微信seo
  • 网站吸引客户百度托管公司
  • 自身网站的平台建设上海做推广的引流公司
  • wordpress添加开场站长之家seo概况查询
  • 河北固安建设局网站站长之家seo综合查询
  • 国内响应式网站欣赏企业宣传片
  • 天津品牌网站建设什么是优化
  • xyz溢价域名最好的网站短视频推广平台有哪些
  • 高清摄影作品网站如何注册网站怎么注册
  • 软件开发工资怎么样池州网站seo
  • 珠海网站建设及优化网络营销有哪些例子
  • wordpress the网站建设优化
  • 企业建立网站需要网站建设网络推广平台
  • 和小男生做的网站经典软文案例
  • 营销建设网站制作推广app的营销方案
  • 龙岩整站优化营销型网站建设目标