Spaces:
Sleeping
Sleeping
File size: 1,408 Bytes
1101b16 |
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 |
import gradio as gr
import requests
import json
import os
# Replace with your actual Play.ht API key and User ID
API_KEY = "your_play_ht_api_key"
USER_ID = "your_play_ht_user_id"
# Function to interact with Play.ht API
def text_to_audio(text):
url = "https://play.ht/api/v2/tts"
headers = {
"Authorization": API_KEY,
"X-User-ID": USER_ID,
"Content-Type": "application/json"
}
# Customize options here (e.g., voice, language, etc.)
data = {
"voice": "en_us-male-1", # Specify a voice of choice
"content": [text],
"speed": 1.0,
"sample_rate": 24000,
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 201:
response_data = response.json()
audio_url = response_data.get("audio_url")
# Fetch the audio file
audio_response = requests.get(audio_url)
audio_path = "output_audio.mp3"
with open(audio_path, "wb") as audio_file:
audio_file.write(audio_response.content)
return audio_path
else:
return f"Error: {response.status_code}, {response.text}"
# Gradio app interface
iface = gr.Interface(
fn=text_to_audio,
inputs="text",
outputs="audio",
title="Text to Speech with Play.ht",
description="Convert text into realistic speech using Play.ht."
)
iface.launch()
|