TOPME / app.py
alexx-ai's picture
Update app.py
237f3c3 verified
Raw
History Blame Contribute Delete
1.73 kB
import gradio as gr
import requests
def convert_voice(audio_path, voice_id): #ymg
url = "https://aivc-api.topmediai.com/vc"
token_response = requests.get("http://ntmtemp.xyz/tts/token.php")
token_response.raise_for_status() # Raise error if request failed
token = token_response.text.strip()
print(token)
headers = {
"accept": "application/json, text/plain, */*",
"authorization": "bbbe05bc467e4f71e62825a8c15fe6201766624429",
"token": "bbbe05bc467e4f71e62825a8c15fe6201766624429",
"x-requested-with": "TTS",
"referer": "https://www.topmediai.com/",
}
data = {
"voice_id": str(voice_id),
"token": "bbbe05bc467e4f71e62825a8c15fe6201766624429",
"is_record": "0"
}
try:
with open(audio_path, "rb") as f:
files = {
"file": ("audio.mp3", f, "audio/mpeg")
}
response = requests.post(url, headers=headers, data=data, files=files)
# Try to parse response
try:
result = response.json()
except Exception as e:
return f"❌ JSON decode error: {e}\nRaw Response:\n{response.text}"
# Handle success or error from API
return result
except Exception as e:
return f"❌ Unexpected error: {str(e)}"
# Gradio UI
interface = gr.Interface(
fn=convert_voice,
inputs=[
gr.Audio(type="filepath", label="Upload Audio (.mp3)"),
gr.Textbox(label="Voice ID", value="179")
],
outputs=gr.Textbox(label="Converted Audio URL"),
title="TopMediai Voice Converter",
description="Upload an audio file and convert it using a selected voice ID."
)
interface.launch()