I'm trying to use gts module in Python
import os from gtts import gTTS
text_to_read = "Hi"
language = 'ko'
slow_audio_speed = False
filename = "my_file.mp3"
def reading_from_user():
user_input = input ("What should I say?")\n")
audio_created =gTTS(text=user_input, lang=language, slow=slow_audio_speed)
audio_created.save(filename)
os.system(f'start {filename}')
if __name__ == '__main__':
reading_from_user()
Questions
In gTTS, do I have to save it as an mp3 file and read it?
Can't I just play the writing on input right away?
gtts tts python
In fact, if you're a Windows user, there's a simpler way.
Use sapi in Windows (https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms723627(v%3Dvs.85)).
Since it is a COM object, you can use the pywin32 (pip install pywin32) module.
import win32com.client
tts = win32com.client.Dispatch("SAPI.SpVoice")
tts.Spoke ("Hashcode requires answer search functionality.")
If you look at the official document, there is a separate entry "Play Sound Right Now".
We have quite a few libraries to make this possible. Write "Hello" on the file resource object and try adding more.
HELP: Issue #26 for discussions and examples on how to play sound.
from gtts import gTTS
from io import BytesIO
mp3_fp = BytesIO()
tts = gTTS('hello', 'en')
tts.write_to_fp(mp3_fp)
# You can now open 'mp3_fp' by treating it as mp3 in the desired audio library.
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
581 PHP ssh2_scp_send fails to send files as intended
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.