代码拉取完成,页面将自动刷新
同步操作将从 小和/文字转语音 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from flask import Flask
from flask import request
from flask import jsonify
app = Flask(__name__)
#version = 1.0
#windows运行命令
#set FLASK_APP=xiaohe
#flask run --host=0.0.0.0
#QQ496631085
import pyttsx3
import hashlib #md5
import pythoncom
@app.route("/")
def xiaohe():
return "<p>你好!此接口是文字生成语音,用于windows环境,详细联系QQ496631085</p>"
@app.route('/tts', methods=['POST', 'GET'])
def tts():
error = None
# return request.values.get('str')
if request.method == 'GET':
if len(request.values.get('str','')) > 0:
pythoncom.CoInitialize()
data = ttsget(request.values.get('str'))
return data #直接返回路径
else:
return "nostr"
if request.method == 'POST':
if len(request.values.get('str','')) > 0:
pythoncom.CoInitialize()
data = ttspost(request.values.get('str'))
return data #直接返回路径
else:
return "nostr"
return "错误"
return render_template('login.html', error=error)
def ttsget(data):
md5 = hashlib.md5(data.encode(encoding='UTF-8')).hexdigest()
engine = pyttsx3.init()
volume = engine.getProperty('volume')
engine.setProperty('volume', volume) #声音大小
# engine.say('The quick brown fox jumped over the lazy dog.')
file_name = md5+'.mp3'
path = '/' + 'static/' + file_name
engine.save_to_file(data ,'.'+path)
engine.runAndWait()
return path
def ttspost(data):
md5 = hashlib.md5(data.encode(encoding='UTF-8')).hexdigest()
engine = pyttsx3.init()
volume = engine.getProperty('volume')
engine.setProperty('volume', volume) #声音大小
# engine.say('The quick brown fox jumped over the lazy dog.')
file_name = md5+'.mp3'
path = '/' + 'static/' + file_name
engine.save_to_file(data ,'.'+path)
engine.runAndWait()
return {"path":path,"file_name":file_name}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。