Spaces:
Runtime error
Runtime error
Update app.py
Browse files195 unmodified lines1961971981992002012022032042022052062052072082092101 unmodified line212213214215216217214218219220221218222223224222223224225225226227227228229230231232233234230235236232233237238239195 unmodified lines
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]: if not input_text or not source_language or not target_language: return None, "Invalid input parameters."
client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")
try: # Make a prediction request to the client result = client.predict( "T2ST", "text", # Since we are doing text-to-speech "text", None, None, input_text,1 unmodified line target_language, api_name="/run" ) except Exception as e: return None, f"Error during prediction: {str(e)}"
# Initialize variables try: translated_text = "" audio_file_path = ""
# Process the result if result: for item in result: if isinstance(item, str): # Check if the item is a URL pointing to an audio file if item.endswith('.mp3'): if not audio_file_path: # Store only the first audio file path audio_file_path = item if item.endswith('.mp3') and not audio_file_path: audio_file_path = item else: # Concatenate the translated text translated_text += item + " " except Exception as e: return None, f"Error processing result: {str(e)}"
if not audio_file_path: return None, "No audio file path found in the result."
return audio_file_path, translated_text.strip() return audio_file_path, translated_text.strip()
except Exception as e: return None, f"Error in text-to-speech conversion: {str(e)}"
def process_image(image_input): # Initialize the Gradio client with the URL of the Gradio serverapp.py+15-12