File size: 1,584 Bytes
c9f1429
8a17995
 
c9f1429
8a17995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9f1429
8a17995
 
 
 
 
 
c9f1429
8a17995
069dbf4
8a17995
 
 
 
 
 
c9f1429
 
 
 
 
 
040ed19
c9f1429
8a17995
040ed19
 
 
 
 
 
8a17995
040ed19
64f266d
c9f1429
d1a3159
 
 
 
 
 
 
 
 
 
c9f1429
8a17995
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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']
    
    # Run the async function in the event loop
    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)