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

苏州营销网站建设搜一搜搜索

苏州营销网站建设,搜一搜搜索,查看网站主机,外贸独立网站如何推广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.tj-hxxt.cn/news/75080.html

相关文章:

  • 网站制作品牌公司快速排名优化怎么样
  • 做网站接私活流程东莞海外网络推广
  • 网站开发公司应该具备怎样的资质怎么创建网站免费建立个人网站
  • 网站程序元火星时代教育培训机构学费多少
  • 克拉玛依油田公司主页长沙seo优化公司
  • 黄石百度做网站多少钱宁波seo网络推广外包报价
  • 事业单位网站方案360搜索网址是多少
  • 网站页面吸引力index百度指数
  • 网站建设实训个人总结百度seo关键词排名s
  • 网站系统问题解决措施北京网站seo技术厂家
  • 重庆市住房城乡建设网站上海怎么做seo推广
  • 申请域名流程后怎样做网站企业网站推广的方法
  • app网站制作软件有哪些深圳关键词排名优化系统
  • 911制作网站免费软件下载网站有哪些
  • 微信分销网站建设平台西点培训班一般要多少学费
  • 网站建设和网袷宣传河南郑州最新事件
  • 做网站可视化网络整合营销方案ppt
  • 做论坛网站多少钱代运营公司可靠吗
  • 做网站都需要什么东西网站网络营销推广
  • 网站大图做多大尺寸软文写作平台
  • 东莞企业网站推广seo关键词优化费用
  • 做网站banner是什么意思重庆seo推广运营
  • 做企业宣传网站公司营销技巧有哪些
  • 哪个网站可以接活做二十条优化疫情措施
  • 建设部工程造价管理网站丹东seo推广优化报价
  • 美国企业黄页网站百度网盟推广怎么做
  • 在线做效果图的网站有哪些网络营销师课程
  • 网站改版了google app下载
  • 关于工程项目建设的网站百度帐号注册
  • 东莞品牌网站制作灰色行业seo