Cleanup and formatting

Done on my phone.
This commit is contained in:
Duane King 2023-11-24 14:58:27 -08:00 committed by GitHub
parent 9ecc380a33
commit 571061b114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
#! python3.7 #! python3.7
import argparse import argparse
import io
import os import os
import numpy as np import numpy as np
import speech_recognition as sr import speech_recognition as sr
@ -10,7 +9,6 @@ import torch
from datetime import datetime, timedelta from datetime import datetime, timedelta
from queue import Queue from queue import Queue
from tempfile import NamedTemporaryFile
from time import sleep from time import sleep
from sys import platform from sys import platform
@ -70,7 +68,6 @@ def main():
record_timeout = args.record_timeout record_timeout = args.record_timeout
phrase_timeout = args.phrase_timeout phrase_timeout = args.phrase_timeout
temp_file = NamedTemporaryFile().name
transcription = [''] transcription = ['']
with source: with source:
@ -110,6 +107,8 @@ def main():
data_queue.queue.clear() data_queue.queue.clear()
# Convert in-ram buffer to something the model can use directly without needing a temp file. # Convert in-ram buffer to something the model can use directly without needing a temp file.
# Convert data from 16 bit wide integers to floating point with a width of 32 bits.
# Clamp the audio stream frequency to a PCM wavelength compatible default of 32768hz max.
audio_np = np.frombuffer(audio_data, dtype=np.int16).astype(np.float32) / 32768.0 audio_np = np.frombuffer(audio_data, dtype=np.int16).astype(np.float32) / 32768.0
# Read the transcription. # Read the transcription.