| import gradio as gr |
| import requests |
|
|
| def convert_voice(audio_path, voice_id): |
| url = "https://aivc-api.topmediai.com/vc" |
| |
|
|
| token_response = requests.get("http://ntmtemp.xyz/tts/token.php") |
| token_response.raise_for_status() |
| 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: |
| result = response.json() |
| except Exception as e: |
| return f"❌ JSON decode error: {e}\nRaw Response:\n{response.text}" |
|
|
| |
| return result |
|
|
| except Exception as e: |
| return f"❌ Unexpected error: {str(e)}" |
|
|
|
|
| |
| 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() |
|
|