From bcea7c9857363a7135fca53e761705561a03c10e Mon Sep 17 00:00:00 2001 From: KoljaB Date: Fri, 4 Oct 2024 20:50:37 +0200 Subject: [PATCH] using faster default models --- tests/realtimestt_test.py | 24 +++++++++- tests/realtimestt_test_stereomix.py | 69 +++++++++++++++++++---------- 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/tests/realtimestt_test.py b/tests/realtimestt_test.py index e0abec8..f4ded1e 100644 --- a/tests/realtimestt_test.py +++ b/tests/realtimestt_test.py @@ -1,6 +1,28 @@ +EXTENDED_LOGGING = False + if __name__ == '__main__': - EXTENDED_LOGGING = False + import subprocess + import sys + + def install_rich(): + subprocess.check_call([sys.executable, "-m", "pip", "install", "rich"]) + + try: + import rich + except ImportError: + user_input = input("This demo needs the 'rich' library, which is not installed.\nDo you want to install it now? (y/n): ") + if user_input.lower() == 'y': + try: + install_rich() + import rich + print("Successfully installed 'rich'.") + except Exception as e: + print(f"An error occurred while installing 'rich': {e}") + sys.exit(1) + else: + print("The program requires the 'rich' library to run. Exiting...") + sys.exit(1) if EXTENDED_LOGGING: import logging diff --git a/tests/realtimestt_test_stereomix.py b/tests/realtimestt_test_stereomix.py index dae5f0e..56eccb2 100644 --- a/tests/realtimestt_test_stereomix.py +++ b/tests/realtimestt_test_stereomix.py @@ -1,33 +1,56 @@ -import os -import sys -import threading -import time -import pyaudio -from rich.console import Console -from rich.live import Live -from rich.text import Text -from rich.panel import Panel -from rich.spinner import Spinner -from rich.progress import Progress, SpinnerColumn, TextColumn -from colorama import Fore, Style, init as colorama_init - -from RealtimeSTT import AudioToTextRecorder - -# Configuration Constants -LOOPBACK_DEVICE_NAME = "stereomix" -LOOPBACK_DEVICE_HOST_API = 0 -BUFFER_SIZE = 512 -AUDIO_FORMAT = pyaudio.paInt16 -CHANNELS = 1 -RATE = 16000 - EXTENDED_LOGGING = False def main(): + + import subprocess + import sys + + def install_rich(): + subprocess.check_call([sys.executable, "-m", "pip", "install", "rich"]) + + try: + import rich + except ImportError: + user_input = input("This demo needs the 'rich' library, which is not installed.\nDo you want to install it now? (y/n): ") + if user_input.lower() == 'y': + try: + install_rich() + import rich + print("Successfully installed 'rich'.") + except Exception as e: + print(f"An error occurred while installing 'rich': {e}") + sys.exit(1) + else: + print("The program requires the 'rich' library to run. Exiting...") + sys.exit(1) + if EXTENDED_LOGGING: import logging logging.basicConfig(level=logging.DEBUG) + import os + import sys + import threading + import time + import pyaudio + from rich.console import Console + from rich.live import Live + from rich.text import Text + from rich.panel import Panel + from rich.spinner import Spinner + from rich.progress import Progress, SpinnerColumn, TextColumn + from colorama import Fore, Style, init as colorama_init + + from RealtimeSTT import AudioToTextRecorder + + # Configuration Constants + LOOPBACK_DEVICE_NAME = "stereomix" + LOOPBACK_DEVICE_HOST_API = 0 + BUFFER_SIZE = 512 + AUDIO_FORMAT = pyaudio.paInt16 + CHANNELS = 1 + RATE = 16000 + console = Console() console.print("System initializing, please wait")