get_rizzed / app.py
1littlecoder's picture
Update app.py
5f4d187 verified
raw
history blame
1.44 kB
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)