RealtimeSTT
RealtimeSTT copied to clipboard
Keyboard hot Key implementation.....
Huge shootout for the work done!! Need help
# Initialize recording state
is_recording = False
# Function to toggle recording state
def toggle_recording():
global is_recording
is_recording = not is_recording
if is_recording:
console.print('[bold green]Recording started...[/bold green]')
else:
console.print('[bold red]Recording stopped.[/bold red]')
try:
while True:
try:
if keyboard.is_pressed('r'): # Press 'r' to start/stop recording
toggle_recording()
sleep(0.5) # Debounce to prevent multiple toggles
if is_recording:
# Simulate text processing
recorder.text(process_text)
sleep(1) # Simulate processing interval
except KeyboardInterrupt:
live.stop()
print("Exiting program...")
break
except KeyboardInterrupt:
live.stop()
console.print("[bold red]Transcription stopped by user. Exiting...[/bold red]")
exit(0)
Tried implemeting using Keyboard Package like the above gives this error: