Tonic commited on
Commit
5e54d9a
1 Parent(s): a2ac4ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -120,6 +120,8 @@ def process_speech(input_language, audio_input):
120
  except Exception as e :
121
  return f"{e}"
122
 
 
 
123
  def convert_text_to_speech(input_text, target_language):
124
  """
125
  Convert text to speech in the specified language and return both the audio file path and the input text.
@@ -137,11 +139,20 @@ def convert_text_to_speech(input_text, target_language):
137
  )
138
 
139
  audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second position
 
 
 
 
 
 
 
 
 
 
140
  return audio_file, input_text
141
  except Exception as e:
142
  return f"An error occurred during text-to-speech conversion: {e}", input_text
143
 
144
-
145
  def save_image(image_input, output_dir="saved_images"):
146
  if not os.path.exists(output_dir):
147
  os.makedirs(output_dir)
 
120
  except Exception as e :
121
  return f"{e}"
122
 
123
+ import os
124
+
125
  def convert_text_to_speech(input_text, target_language):
126
  """
127
  Convert text to speech in the specified language and return both the audio file path and the input text.
 
139
  )
140
 
141
  audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second position
142
+
143
+ # Shorten the file name to 12 characters
144
+ max_length = 12 # Maximum file name length
145
+ dir_name, file_name = os.path.split(audio_file)
146
+ if len(file_name) > max_length:
147
+ # Keep the file extension if present
148
+ file_extension = os.path.splitext(file_name)[1]
149
+ file_name = file_name[:max_length - len(file_extension)] + file_extension
150
+ audio_file = os.path.join(dir_name, file_name)
151
+
152
  return audio_file, input_text
153
  except Exception as e:
154
  return f"An error occurred during text-to-speech conversion: {e}", input_text
155
 
 
156
  def save_image(image_input, output_dir="saved_images"):
157
  if not os.path.exists(output_dir):
158
  os.makedirs(output_dir)