|
from flask import Flask, request, jsonify |
|
import requests |
|
import uvicorn |
|
app = Flask(__name__) |
|
RQ = requests.Session() |
|
|
|
|
|
def GenAudio( |
|
text:str, |
|
model:str |
|
)-> dict: |
|
|
|
url = "https://deepgram.com/api/ttsAudioGeneration" |
|
|
|
headers = { |
|
"content-type": "application/json", |
|
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" |
|
} |
|
|
|
|
|
payload = { |
|
"text": text, |
|
"model": model, |
|
"demoType": "landing-page", |
|
"params": "tag=landingpage-product-texttospeech" |
|
} |
|
|
|
response = RQ.post(url, json=payload, headers=headers) |
|
|
|
if response.status_code == 200: |
|
print("Request was successful.") |
|
return response.json() |
|
|
|
else: |
|
print(f"Request failed with status code: {response.status_code}") |
|
|
|
|
|
|
|
|
|
@app.route('/tts', methods=['POST']) |
|
def tts(): |
|
"""Handles POST requests for text-to-speech conversion.""" |
|
data = request.get_json() |
|
model = data.get('model', 'aura-luna-en') |
|
if not data or 'text' not in data: |
|
return jsonify({'error': 'Text is required'}), 400 |
|
|
|
text = data['text'] |
|
|
|
|
|
audio_base64 = GenAudio(text, model) |
|
|
|
return audio_base64, 200 |
|
|
|
@app.route('/ttsmoderls', methods=['GET']) |
|
def ttsmoderls(): |
|
|
|
return jsonify( |
|
{1 : "aura-luna-en", |
|
2 : "aura-asteria-en", |
|
3 : "aura-arcas-en", |
|
4 : "aura-zeus-en"} |
|
) |
|
|
|
if __name__ == '__main__': |
|
|
|
app.run(debug=True, port=5000) |