Add a bunch of test files

This commit is contained in:
2023-04-07 21:50:01 +00:00
parent 89cb732e42
commit 41bc6015bf
7 changed files with 557 additions and 0 deletions

61
read_file.py Normal file
View File

@@ -0,0 +1,61 @@
import os
import importlib
import threading
import time
import whisper
import traceback
import audio
print('Loading whisper model...')
start = time.time()
model = whisper.load_model('medium')
print('Done after', time.time() - start, 's')
# array of audio chunks
audio_chunks = [bytearray()]
def read_audio_thread():
global audio_chunks
while True:
with open('whispercppexample.pcm', 'rb') as f:
while True:
data = f.read(1920)
if not data:
break
audio.process_pcm(audio_chunks, data)
time.sleep(0.04)
def process_stream_thread():
global audio_chunks
while True:
try:
audio.process_stream(audio_chunks, model)
except BaseException as e:
print('exception')
traceback.print_exc()
print('sleeping...')
time.sleep(5)
def monitor_module():
mod_time = os.path.getmtime('audio.py')
while True:
if os.path.getmtime('audio.py') > mod_time:
mod_time = os.path.getmtime('audio.py')
print('Change detected, reloading.')
importlib.reload(audio)
time.sleep(1)
t1 = threading.Thread(target=read_audio_thread)
t2 = threading.Thread(target=process_stream_thread)
t3 = threading.Thread(target=monitor_module)
t1.start()
t2.start()
t3.start()
while True:
pass