Spaces:
Runtime error
Runtime error
Update voice_assistent.py
Browse files- voice_assistent.py +13 -39
voice_assistent.py
CHANGED
@@ -10,14 +10,14 @@ from pydub import AudioSegment
|
|
10 |
from pydub.playback import play
|
11 |
import urllib.request
|
12 |
|
13 |
-
PATH_TO_MODEL = "
|
14 |
-
PATH_TO_OUTPUT = "C:/Users/user/Desktop/deepfake_sirius/materials/audio"
|
15 |
|
16 |
|
17 |
k = "sk-YOVNQzHmpga9My3dwlSo9BQN907TuPZQXcHn50ztigTwm3I2"
|
18 |
files = [
|
19 |
-
("input_face", open("C:\\Users\\user\\Desktop\\deepfake_sirius\\materials\\scale_1200.jpg", "rb")),
|
20 |
-
("input_audio", open("C:\\Users\\user\\Desktop\\deepfake_sirius\\materials\\audio\\output.wav", "rb")),
|
21 |
]
|
22 |
payload = {}
|
23 |
|
@@ -32,41 +32,15 @@ class VoiceGenerator:
|
|
32 |
return path
|
33 |
|
34 |
def record_and_recognize_audio(*args: tuple):
|
35 |
-
"""
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
try:
|
45 |
-
print("Listening...")
|
46 |
-
audio = recognizer.listen(microphone, 5, 5)
|
47 |
-
|
48 |
-
with open("microphone-results.wav", "wb") as file:
|
49 |
-
file.write(audio.get_wav_data())
|
50 |
-
|
51 |
-
except speech_recognition.WaitTimeoutError:
|
52 |
-
print("Can you check if your microphone is on, please?")
|
53 |
-
return
|
54 |
-
|
55 |
-
# использование online-распознавания через Google
|
56 |
-
try:
|
57 |
-
print("Started recognition...")
|
58 |
-
recognized_data = recognizer.recognize_google(audio, language="ru").lower()
|
59 |
-
|
60 |
-
except speech_recognition.UnknownValueError:
|
61 |
-
pass
|
62 |
-
|
63 |
-
# в случае проблем с доступом в Интернет происходит попытка
|
64 |
-
# использовать offline-распознавание через Vosk
|
65 |
-
except speech_recognition.RequestError:
|
66 |
-
print("Trying to use offline recognition...")
|
67 |
-
recognized_data = use_offline_recognition()
|
68 |
-
|
69 |
-
return recognized_data
|
70 |
|
71 |
|
72 |
def use_offline_recognition():
|
|
|
10 |
from pydub.playback import play
|
11 |
import urllib.request
|
12 |
|
13 |
+
PATH_TO_MODEL = "vosk-model-tts-ru-0.4-multi"
|
14 |
+
PATH_TO_OUTPUT = "C:/Users/user/Desktop/deepfake_sirius/materials/audio" #TODO: IT
|
15 |
|
16 |
|
17 |
k = "sk-YOVNQzHmpga9My3dwlSo9BQN907TuPZQXcHn50ztigTwm3I2"
|
18 |
files = [
|
19 |
+
("input_face", open("C:\\Users\\user\\Desktop\\deepfake_sirius\\materials\\scale_1200.jpg", "rb")), #TODO: IT
|
20 |
+
("input_audio", open("C:\\Users\\user\\Desktop\\deepfake_sirius\\materials\\audio\\output.wav", "rb")), #TODO: IT
|
21 |
]
|
22 |
payload = {}
|
23 |
|
|
|
32 |
return path
|
33 |
|
34 |
def record_and_recognize_audio(*args: tuple):
|
35 |
+
# with open("microphone-results.wav", "wb") as file:
|
36 |
+
# file.write(audio.get_wav_data())
|
37 |
+
try:
|
38 |
+
recognized_data = recognizer.recognize_google(audio, language="ru").lower()
|
39 |
+
except speech_recognition.UnknownValueError:
|
40 |
+
pass
|
41 |
+
except speech_recognition.RequestError:
|
42 |
+
recognized_data = use_offline_recognition()
|
43 |
+
return recognized_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
|
46 |
def use_offline_recognition():
|