import gradio as gr import requests import urllib.request from pydub import AudioSegment import numpy as np import os def function1(prompt): response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={ "data": [ prompt, ]}).json() data = response["data"][0] response = requests.post("https://matthijs-speecht5-tts-demo.hf.space/run/predict", json={ "data": [ data, "KSP (male)", ] }).json() data = response["data"][0]["name"] data = "https://matthijs-speecht5-tts-demo.hf.space/file=" + data # Download the audio file and save it in WAV format file_name, headers = urllib.request.urlretrieve(data, "speech.wav") # Load the audio file using pydub sound = AudioSegment.from_wav("speech.wav") # Set the path and file name for the converted MP3 file mp3_file = "speech.mp3" # Export the audio in MP3 format sound.export(mp3_file, format="mp3") # Delete the WAV file os.remove("speech.wav") # Return the path to the MP3 file return os.path.abspath(mp3_file)