playht / pyht

PlayHT Python SDK - AI Text-to-Speech Streaming & Voice Cloning API
https://play.ht/
Apache License 2.0
178 stars 23 forks source link

Stop running after done generating #39

Open fakerybakery opened 7 months ago

fakerybakery commented 7 months ago

Hi, I'm using this code:

with open(f'{x}.wav', 'wb') as f:
    for chunk in client.tts("Can you tell me your account email or, ah your phone number?", options):
        if not chunk:
            break
        print(type(chunk))
        f.write(chunk)

However it does not terminate the script after the audio has finished generating, how can I detect when the audio is done generating and stop? Thank you!

cc @NCarrollPlay @mahmoudfelfel

sadmoody commented 6 months ago

You don't really need that break statement in there. You are getting out of the loop when it's done writing.

The reason your script does not stop executing is because the client is holding it open. If you add client.close() after your loop, your program should terminate correctly!

Probably should update the example code.