VOSK initialization:
Sets up the voice input stream for the voice assistant.
#START OF VOSK CONFIG SECTION
FRAME_RATE = 16000
CHANNELS=1
#Get microphone ID if needed, by default vosk should use whatever the machines default input device is.
#python -m sounddevice devicelist
#Model = location of your specific vosk model (vosk-model-en-0.22 is bugged and prefixes every input with "the". vosk-model-en-0.21 works great)
model = Model(r'/mnt/Storage1/Python/vosk/model')
recognizer = KaldiRecognizer(model, 16000)
cap = pyaudio.PyAudio()
#Using default audio device
stream = cap.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8192)
#With a microphone ID specified, shouldn't be required but here it is.
#stream = cap.open(input_device_index=35 ,format=pyaudio.paInt32, channels=1, rate=48000, input=True, frames_per_buffer=8192)
stream.start_stream()
#END OF VOSK CONFIG SECTION
Conversion of the VOSK recognizer voice stream to data for use in my programs.
stream from above is read and assigned to the data variable.
while True:
data = stream.read(4096)
if recognizer.AcceptWaveform(data):
text = recognizer.Result()
print(f"' {text[14:-3]} '")
text=(f" {text[14:-3]} ")
#Option to log all microphone input to file, functions as a
transcription tool.
#voice_log.write(text +"\n")