capradeepgujaran commited on
Commit
5fad48b
1 Parent(s): 601f904

Update openai_tts_tool.py

Browse files
Files changed (1) hide show
  1. openai_tts_tool.py +5 -4
openai_tts_tool.py CHANGED
@@ -1,7 +1,7 @@
1
  from openai import OpenAI
2
  import os
3
 
4
- def generate_audio_and_text(api_key, input_text, model_name, voice_type, voice_speed, output_option):
5
  """
6
  Generate audio and text files from input text using OpenAI's TTS API.
7
 
@@ -11,6 +11,7 @@ def generate_audio_and_text(api_key, input_text, model_name, voice_type, voice_s
11
  model_name (str): OpenAI model name
12
  voice_type (str): Voice type for TTS
13
  voice_speed (float): Speed of speech
 
14
  output_option (str): Output type ('audio', 'script_text', or 'both')
15
 
16
  Returns:
@@ -41,7 +42,7 @@ def generate_audio_and_text(api_key, input_text, model_name, voice_type, voice_s
41
  )
42
 
43
  # Save the audio to a temporary file
44
- audio_path = os.path.join(temp_dir, f"output_{hash(input_text)}.mp3")
45
  with open(audio_path, "wb") as f:
46
  for chunk in speech_response.iter_bytes():
47
  f.write(chunk)
@@ -51,12 +52,12 @@ def generate_audio_and_text(api_key, input_text, model_name, voice_type, voice_s
51
  # Save the input text as a script file
52
  script_file = None
53
  if output_option in ["script_text", "both"]:
54
- script_path = os.path.join(temp_dir, f"script_{hash(input_text)}.txt")
55
  with open(script_path, "w", encoding='utf-8') as f:
56
  f.write(input_text)
57
  script_file = script_path
58
 
59
- status_message = "Generation completed successfully!"
60
  return audio_file, script_file, status_message
61
 
62
  except Exception as e:
 
1
  from openai import OpenAI
2
  import os
3
 
4
+ def generate_audio_and_text(api_key, input_text, model_name, voice_type, voice_speed, language, output_option):
5
  """
6
  Generate audio and text files from input text using OpenAI's TTS API.
7
 
 
11
  model_name (str): OpenAI model name
12
  voice_type (str): Voice type for TTS
13
  voice_speed (float): Speed of speech
14
+ language (str): Language code for synthesis
15
  output_option (str): Output type ('audio', 'script_text', or 'both')
16
 
17
  Returns:
 
42
  )
43
 
44
  # Save the audio to a temporary file
45
+ audio_path = os.path.join(temp_dir, f"output_{hash(input_text)}_{language}.mp3")
46
  with open(audio_path, "wb") as f:
47
  for chunk in speech_response.iter_bytes():
48
  f.write(chunk)
 
52
  # Save the input text as a script file
53
  script_file = None
54
  if output_option in ["script_text", "both"]:
55
+ script_path = os.path.join(temp_dir, f"script_{hash(input_text)}_{language}.txt")
56
  with open(script_path, "w", encoding='utf-8') as f:
57
  f.write(input_text)
58
  script_file = script_path
59
 
60
+ status_message = f"Generation completed successfully in {language}!"
61
  return audio_file, script_file, status_message
62
 
63
  except Exception as e: