Answer the question
In order to leave comments, you need to log in
How to make a call by voice?
Help me write code that will work if I say: Alice
I have a problem, the program works with a bang, but the microphone will turn on and off each time until I say some question
I need it to be when I say the name: "alisa", then the microphone will turn on to listen to the question and if a certain time is reached, then turn off the microphone
The assistant works offline if anything, because there is not always an Internet
connection Here is the code
import random
import sys
from vosk import Model, KaldiRecognizer # оффлайн-распознавание от Vosk
import speech_recognition # распознавание пользовательской речи (Speech-To-Text)
import wave # создание и чтение аудиофайлов формата wav
import json # работа с json-файлами и json-строками
import os # работа с файлами
import subprocess
import requests
one = 'echo Алиса слушает |RHVoice-test -p anna'
subprocess.call(one, shell=True)
def assistent(*args: tuple):
with microphone:
value = ""
recognizer.adjust_for_ambient_noise(microphone, duration=1)
try:
audio = recognizer.listen(microphone, 7, 5)
with open("voices-my.wav", "wb") as file:
file.write(audio.get_wav_data())
except speech_recognition.WaitTimeoutError:
print('Повтори')
try:
audio_file = wave.open("voices-my.wav", "rb")
model = Model("images/vosk-model-small-ru-0.15")
offline = KaldiRecognizer(model, audio_file.getframerate())
data = audio_file.readframes(audio_file.getnframes())
if len(data) > 0:
if offline.AcceptWaveform(data):
value = offline.Result()
dicts = open('body.json', 'r')
opening = json.load(dicts)
if 'привет' in value:
subprocess.call('echo '+random.choice(opening['привет'])+'|RHVoice-test -p anna', shell=True)
elif 'как дела' in value:
subprocess.call('echo '+random.choice(opening['как дела'])+'|RHVoice-test -p anna', shell=True)
elif 'пока' in value:
subprocess.call('echo '+random.choice(opening['пока']) +'|RHVoice-test -p anna', shell=True)
sys.exit(1)
except:
error = 'echo не могу распознать речь| RHVoice-test -p anna'
subprocess.call(error, shell=True)
return value
if __name__ == "__main__":
recognizer = speech_recognition.Recognizer()
microphone = speech_recognition.Microphone()
while True:
voice_input = assistent()
os.remove("voices-my.wav")
print(voice_input)
Answer the question
In order to leave comments, you need to log in
The microphone must always be kept on, otherwise how to recognize the keyword. An example of streaming recognition from a microphone with wax can be found here:
https://github.com/alphacep/vosk-api/blob/master/p...
speech_recognition is better not to use, it is not adapted for streaming recognition.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question