Spaces:
Runtime error
Runtime error
Update app.py
Browse files119 unmodified lines1201211221231241231241271251261271287 unmodified lines136137138141139140141143144142143146147148149150144145146147148152149150151152153154155156119 unmodified lines except Exception as e : return f"{e}"
import os
def 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. 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 lines api_name="/run" # API name )
audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second position # Assuming the audio file path is in the second position of the result audio_file = text_to_speech_result[1]
# Shorten the file name to 12 characters max_length = 12 # Maximum file name length max_length = 25 dir_name, file_name = os.path.split(audio_file) if len(file_name) > max_length: # Keep the file extension if present file_extension = os.path.splitext(file_name)[1] file_name = file_name[:max_length - len(file_extension)] + file_extension audio_file = os.path.join(dir_name, file_name) file_extension = os.path.splitext(file_name)[1] shortened_file_name = file_name[:max_length - len(file_extension)] + file_extension shortened_audio_file = os.path.join(dir_name, shortened_file_name)
# Return the shortened audio file path and the input text return audio_file, input_text return shortened_audio_file, input_text except Exception as e: return f"An error occurred during text-to-speech conversion: {e}", input_text
def save_image(image_input, output_dir="saved_images"): if not os.path.exists(output_dir): os.makedirs(output_dir)app.py+10-12