File size: 972 Bytes
98a6b3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from elevenlabs.client import ElevenLabs  # Import ElevenLabs from elevenlabs.client
from elevenlabs import VoiceSettings

def text_to_speech(api_key, text):
    client = ElevenLabs(api_key=api_key)
    audio = client.text_to_speech.convert(
        voice_id="pMsXgVXv3BLzUgSXRplE",
        optimize_streaming_latency="0",
        output_format="mp3_22050_32",
        text=text,
        voice_settings=VoiceSettings(
            stability=0.1,
            similarity_boost=0.3,
            style=0.2,
        ),
    )
    return audio

iface = gr.Interface(
    fn=text_to_speech,
    inputs=[
        gr.Textbox(label="API Key"),
        gr.Textbox(label="Text to Convert to Speech")
    ],
    outputs=gr.Audio(label="Generated Speech"),
    title="Text to Speech with Eleven Labs",
    description="Enter your Eleven Labs API key and the text you'd like to convert to speech. The output will be an audio file of the spoken text."
)

iface.launch()