pyht icon indicating copy to clipboard operation
pyht copied to clipboard

Stop running after done generating

Open fakerybakery opened this issue 1 year ago • 1 comments

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

fakerybakery avatar Mar 27 '24 02:03 fakerybakery

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.

sadmoody avatar Apr 23 '24 12:04 sadmoody