diff --git a/Uptated-Prototype/TTS-Script-PiperTTS 2nd.py b/Uptated-Prototype/TTS-Script-PiperTTS 2nd.py index 7a7a053..10eb645 100644 --- a/Uptated-Prototype/TTS-Script-PiperTTS 2nd.py +++ b/Uptated-Prototype/TTS-Script-PiperTTS 2nd.py @@ -5,6 +5,7 @@ import os import subprocess import time from piper.voice import SynthesisConfig +import atexit result = subprocess.run(["xsel"], capture_output=True, text=True) # In Theory grab selected text into Varible called TextToSpeak #print(result) # In Theory grab selected text and print ot to terminal @@ -33,10 +34,8 @@ first_chunk = next(chunks) # Get the first chunk to set up audio stream configur try: - count = 1 - for chunk in chunks: # Play subsequent chunks of audio - count += 1 - print(count) # Print the amount of chunks + result = len(list(chunks)) + print(result) # Print the amount of chunks except: print("Failed getting Chunk Count") try: @@ -57,7 +56,13 @@ stream.write(first_chunk.audio_int16_bytes) # Play the first chunk for chunk in chunks: # Play subsequent chunks of audio stream.write(chunk.audio_int16_bytes) -# Cleanup -stream.stop_stream() -stream.close() -p.terminate() \ No newline at end of file + +# Function called on Exit +def Registered_Exit(): + # Cleanup + stream.stop_stream() + stream.close() + p.terminate() + +# Regestering Exit +atexit.register(Registered_Exit) \ No newline at end of file