网站建设性能指标,阿里云主机wordpress,怎么做淘宝网站教程,wordpress 只收录首页背景#xff1a; 在进行MoneyPrinter项目国内环境搭建中#xff0c;发现框架本身的TikTok文字转语音部分的代码已经不能用了#xff0c;最好是能够找到国内网站的替换方案。
实现#xff1a; 感谢网站#xff1a;https://www.text-to-speech.cn/
代码#xff1a;
# -*…背景 在进行MoneyPrinter项目国内环境搭建中发现框架本身的TikTok文字转语音部分的代码已经不能用了最好是能够找到国内网站的替换方案。
实现 感谢网站https://www.text-to-speech.cn/
代码
# -*- coding:UTF-8 -*-ProjectName :FileName : tts-demoDescription : 文字转语音Time : 2024/5/10 14:44Author : Qredsun
import time
import uuid
from urllib.parse import urlencodeimport requests
from loguru import loggerclass textToSpeech():BASE_URL https://www.text-to-speech.cn/HEADER {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0,Accept: */*,Accept-Language: zh-CN,zh;q0.8,zh-TW;q0.7,zh-HK;q0.5,en-US;q0.3,en;q0.2,X-Requested-With: XMLHttpRequest,Origin: BASE_URL,Connection: keep-alive,Referer: BASE_URL,Sec-Fetch-Dest: empty,Sec-Fetch-Mode: cors,Sec-Fetch-Site: same-origin,}def get_speaker_list(self):url f{self.BASE_URL}/getSpeekList.phpresponse requests.get(url, headersself.HEADER)if response.ok:response_json response.json()speaker_list response_jsonlogger.debug(f返回获取音频配置列表{speaker_list})logger.info(转换接口使用的是语言key、ShortName)return speaker_listlogger.error(f获取音频配置失败{response.text})return Nonedef convert_voice(self, txt这是一段对话, /, *, languageEnglish (United States), voiceAvaMultilingualNeural,file_nameNone):logger.debug(f待转化音频的内容{txt})url f{self.BASE_URL}/getSpeek.phppayload {language: language,voice: voice,text: txt,role: 0,style: 0,rate: 0,pitch: 0,kbitrate: audio-16khz-32kbitrate-mono-mp3,silence: ,styledegree: 1,volume: 75,predict: 0,user_id: ,yzm: ,replice: 1,}cookies {Hm_lvt_b38a22175a63114a18d55183d7ddb4c4: int(time.time()),Hm_lpvt_b38a22175a63114a18d55183d7ddb4c4: int(time.time()),language: language,voice: voice,kbitrate: audio-16khz-32kbitrate-mono-mp3,role: 0,style: 0,speed: 0,pitch: 0,checkuser: time.strftime(%Y-%m-%d, time.localtime())}cookies_str urlencode(cookies)# logger.debug(fcookies: {cookies_str})headers {Cookie: cookies_str,Content-Type: application/x-www-form-urlencoded; charsetUTF-8}headers.update(self.HEADER)response requests.request(POST, url, headersheaders, datapayload)if not response.ok:logger.error(f转换音频失败{response.text})return Noneresponse_json response.json()if response_json[code] 200:url response_json[download]logger.info(f返回音频下载连接{url})if file_name:self.save_voice(url, video_idfile_name)return urldef save_voice(self, url, /, *, video_idNone):try:video_id video_id if video_id else uuid.uuid4()with open(video_id, wb) as f:f.write(requests.get(url).content)logger.info(f音频已保存至{video_id})except Exception as e:logger.error(f音频保存失败{e})if __name__ __main__:c2v textToSpeech()# c2v.get_speaker_list() # 获取可用的语言及声音url c2v.convert_voice(我真的是服了, save_voiceTrue)