Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
from requests.exceptions import ConnectionError, SSLError, Timeout | |
def clone_voice(text, audio_file): | |
try: | |
# Prepare the payload | |
payload = { | |
'text': text, | |
'language': 'ar' # Fixed to Arabic as per original app | |
} | |
# Prepare the files | |
files = { | |
'audio_file': ('audio.wav', audio_file, 'audio/wav') | |
} | |
# API endpoint | |
api_url = "https://tellergen.com/api/clone-voice" | |
# Make the request | |
response = requests.post( | |
api_url, | |
data=payload, | |
files=files, | |
verify=False, # Disable SSL verification | |
timeout=30 # Set timeout to 30 seconds | |
) | |
response.raise_for_status() | |
# Check if the request was successful | |
if response.status_code == 200: | |
content_type = response.headers.get('Content-Type') | |
if 'audio' in content_type: | |
# Save the audio response to a temporary file | |
return response.content | |
else: | |
try: | |
return str(response.json()) | |
except ValueError: | |
return response.text | |
else: | |
return f"API request failed with status code {response.status_code}" | |
except ConnectionError: | |
return "Connection error. Please check your internet connection and try again." | |
except SSLError: | |
return "SSL Error occurred. Please try again later." | |
except Timeout: | |
return "Request timed out. Please try again later." | |
except Exception as e: | |
return f"An unexpected error occurred: {str(e)}" | |
# Create Gradio interface | |
default_text = "مرحباً بكم في تطبيق استنساخ الصوت. يمكنك استخدام هذا التطبيق لإنشاء نسخة من صوتك باللغة العربية." | |
demo = gr.Interface( | |
fn=clone_voice, | |
inputs=[ | |
gr.Textbox(label="Text", value=default_text), | |
gr.Audio(label="Upload Audio File", type="filepath") | |
], | |
outputs=gr.Audio(label="Cloned Voice"), | |
title="📢 Voice Cloning Application", | |
description="Enter the details below and upload an audio file to clone the voice." | |
) | |
if __name__ == "__main__": | |
demo.launch(share=True) | |