pndurette / gTTS

Python library and CLI tool to interface with Google Translate's text-to-speech API
http://gtts.readthedocs.org/
MIT License
2.33k stars 361 forks source link

Add ability to adjust speed #420

Open KonerDev opened 1 year ago

KonerDev commented 1 year ago

Prerequisites

Proposed Behaviour

I suggest adding a feature that allows users to modify the speed of the tts output.

tts = gTTS(text='Hello World!', lang='en', speed=2.1)
tts.save(name)

Context

There is currently no way to make the speed particularly fast. Can you please add that?

hanzigs commented 1 year ago

speed will be a nice feature, Is there a way to give pause in the sentence?

ILG2021 commented 1 year ago

still needs the feature.

pndurette commented 1 year ago

Google Translate only has two arbitrary speech speed options ("normal" and "slow"), to modify the speed, gTTS would need to tap into some sound libraries, which it currently leaves to the developer.

I don't think I'd want to add it in (unless I add some extra optional dependancies, perhaps), but I could eventually provide examples of how achieve it, TBD. Will put this documentation.

ILG2021 commented 1 year ago

I have implement it by ffmpeg:

output_audio_file = "output_audio.mp3"
ffmpeg_command = ["ffmpeg", "-y", "-i", temp_audio_file, "-filter:a", "atempo=1.3", output_audio_file]
subprocess.run(ffmpeg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)