@@ -52,11 +52,37 @@ def generate_audio_mac_wav(prompt: str) -> bytes:
5252 return audio_bytes
5353
5454
55+ def generate_audio_cross_platform (prompt : str ) -> bytes :
56+ """
57+ Generate an audio file from the provided prompt using gTTS for cross-platform support.
58+
59+ Parameters:
60+ prompt (str): Text to convert into audio.
61+
62+ Returns:
63+ bytes: The audio data in MP3 format.
64+ """
65+ from gtts import gTTS # Import gTTS for cross-platform support
66+
67+ tts = gTTS (text = prompt , lang = "en" )
68+ temp_mp3_path = f"temp_audio_{ uuid .uuid4 ().hex } .mp3"
69+ tts .save (temp_mp3_path )
70+
71+ try :
72+ with open (temp_mp3_path , "rb" ) as f :
73+ audio_bytes = f .read ()
74+ finally :
75+ if os .path .exists (temp_mp3_path ):
76+ os .remove (temp_mp3_path )
77+
78+ return audio_bytes
79+
80+
5581@cache_to_disk ()
5682def generate_audioform (prompt : str ) -> bytes :
5783 """
5884 Generate an audio file from the provided prompt in WAV format.
59- Uses macOS 'say' command if the operating system is macOS.
85+ Uses macOS 'say' command if the operating system is macOS, otherwise uses gTTS .
6086
6187 Parameters:
6288 prompt (str): Text to convert into audio.
@@ -67,9 +93,11 @@ def generate_audioform(prompt: str) -> bytes:
6793 current_os = platform .system ()
6894 if current_os == "Darwin" : # macOS
6995 return generate_audio_mac_wav (prompt )
96+ elif current_os in ["Windows" , "Linux" ]:
97+ return generate_audio_cross_platform (prompt )
7098 else :
7199 raise NotImplementedError (
72- "Audio generation is only supported on macOS for now."
100+ "Audio generation is only supported on macOS, Windows, and Linux for now."
73101 )
74102
75103
0 commit comments