File size: 848 Bytes
0da1480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4b8a9a
 
0da1480
 
 
 
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
import io
import os

import gradio as gr
from groq import Groq

CLIENT = Groq(api_key=os.environ.get("GROQ_API_KEY"))
RESPONSE_FORMAT = os.environ.get("RESPONSE_FORMAT", "wav")
MODEL = os.environ.get("MODEL", "playai-tts")
VOICE = os.environ.get("VOICE", "Fritz-PlayAI")


def generate_audio(text):
    """Generate audio from text and return it as a binary stream"""
    response = CLIENT.audio.speech.create(
        model=MODEL,
        voice=VOICE,
        input=text,
        response_format=RESPONSE_FORMAT,
    )
    return io.BytesIO(response.parse()).getvalue()


app = gr.Interface(
    fn=generate_audio,
    inputs=gr.Textbox(label="Text"),
    outputs=gr.Audio(label="Audio"),
    title="Text to Speech",
    description="Generate audio from text and return the audio url",
)

if __name__ == "__main__":
    app.launch(mcp_server=True)