File size: 1,439 Bytes
1101b16
 
 
 
 
 
b326bed
 
1101b16
99f3aa9
 
 
 
 
 
 
5f4d187
99f3aa9
1101b16
99f3aa9
 
1101b16
99f3aa9
1101b16
 
99f3aa9
 
 
 
 
1101b16
 
99f3aa9
1101b16
 
99f3aa9
1101b16
99f3aa9
1101b16
99f3aa9
1101b16
 
99f3aa9
 
1101b16
 
e0c831f
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
import gradio as gr
import requests
import json
import os

# Replace with your actual Play.ht API key and User ID
API_KEY = os.getenv('PLAY_API_KEY')
USER_ID = os.getenv('PLAY_USER_ID')

def text_to_speech(text):
    url = "https://api.play.ht/api/v2/tts/stream"
    
    # Customize the payload based on your Play.ht account setup
    payload = {
        "voice": "s3://voice-cloning-zero-shot/d9ff78ba-d016-47f6-b0ef-dd630f59414e/female-cs/manifest.json", # Replace with your desired voice
        "output_format": "mp3",
        "text": text  # Text to be converted to speech
    }
    headers = {
        "accept": "audio/mpeg",
        "content-type": "application/json",
        "Authorization": API_KEY,
        "X-User-ID": USER_ID
    }
    
    response = requests.post(url, json=payload, headers=headers)
    
    # Check if the response was successful
    if response.status_code == 200:
        # Save the audio content to a file
        audio_path = "output_audio.mp3"
        with open(audio_path, "wb") as audio_file:
            audio_file.write(response.content)
        return audio_path
    else:
        return f"Error: {response.status_code} - {response.text}"

# Set up Gradio Interface
iface = gr.Interface(
    fn=text_to_speech,
    inputs="text",
    outputs="audio",
    title="Play.ht Text-to-Speech",
    description="Convert text into speech using Play.ht's TTS streaming API."
)

iface.launch(debug = True)