You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from flask import Flask, request, send_file
from gtts import gTTS
import os
from datetime import datetime
import time
app = Flask(__name__)
@app.route('/tts', methods=['GET'])
def tts():
# Get the 'text' parameter from the GET request
text = request.args.get('text')
if not text:
return {"error": "Missing 'text' parameter"}, 400
# Create a timestamped filename
timestamp = datetime.now().strftime("%d%m%y_%H%M%S")
filename = f"gttsmp3_{timestamp}.mp3"
try:
# Convert the text to Thai speech using gTTS
tts = gTTS(text, lang="th")
# Save the audio to a temporary file
tts.save(filename)
# Wait until the file is completely saved (optional)
time.sleep(1) # Simple wait, could be adjusted or improved
# Send the MP3 file as a response
return send_file(filename, as_attachment=False)
except ValueError as ve:
return {"error": f"Value error: {str(ve)}"}, 400
except IOError as ie:
return {"error": f"File I/O error: {str(ie)}"}, 500
except Exception as e:
return {"error": f"An unexpected error occurred: {str(e)}"}, 500
# finally:
# Clean up the temporary file if it exists
# if os.path.exists(filename):
# os.remove(filename)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
The text was updated successfully, but these errors were encountered:
3000_common_volubilis_thai3.json
2 我用自製的google translate TTS 語音api.
5.然後試下。除了每節第一個字配對了,之二個字之後都讀出N+1的讀音。
6. 把。usePrefetchPronunciationSound(nextWord?.name) 取消後變正常可用。
以下是gtts的自製 讀音API
The text was updated successfully, but these errors were encountered: