Spaces:
Runtime error
Runtime error
Update app.py
Browse files119 unmodified lines1201211221231241251261271281291307 unmodified lines138139140141142143144145146147148149150151152153154155156157158119 unmodified linesexcept Exception as e :return f"{e}"import osdef convert_text_to_speech(input_text, target_language):"""Convert text to speech in the specified language and return both the audio file path and the input text."""try:text_to_speech_result = seamless_client.predict(7 unmodified linesapi_name="/run" # API name)audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second position# Shorten the file name to 12 charactersmax_length = 12 # Maximum file name lengthdir_name, file_name = os.path.split(audio_file)if len(file_name) > max_length:# Keep the file extension if presentfile_extension = os.path.splitext(file_name)[1]file_name = file_name[:max_length - len(file_extension)] + file_extensionaudio_file = os.path.join(dir_name, file_name)return audio_file, input_textexcept Exception as e:return f"An error occurred during text-to-speech conversion: {e}", input_textdef save_image(image_input, output_dir="saved_images"):if not os.path.exists(output_dir):os.makedirs(output_dir)119 unmodified lines1201211221231241251261271287 unmodified lines136137138139140141142143144145146147148149150151152153154155156119 unmodified linesexcept Exception as e :return f"{e}"def convert_text_to_speech(input_text, target_language):"""Convert text to speech in the specified language and return the audio file path and the input text."""try:text_to_speech_result = seamless_client.predict(7 unmodified linesapi_name="/run" # API name)# Assuming the audio file path is in the second position of the resultaudio_file = text_to_speech_result[1]max_length = 25dir_name, file_name = os.path.split(audio_file)file_extension = os.path.splitext(file_name)[1]shortened_file_name = file_name[:max_length - len(file_extension)] + file_extensionshortened_audio_file = os.path.join(dir_name, shortened_file_name)# Return the shortened audio file path and the input textreturn shortened_audio_file, input_textexcept Exception as e:return f"An error occurred during text-to-speech conversion: {e}", input_textdef save_image(image_input, output_dir="saved_images"):if not os.path.exists(output_dir):os.makedirs(output_dir)
app.py+10-12