Добрый день, у меня проблемы с обучением ИИ. Я украл весь код из одного видео и пытаюсь сделать его лучше.
вот код:
Код: Выделить всё
import torch
import sounddevice as sd
import speech_recognition as sr
import time
import numpy
from glob import glob
device = torch.device('cpu')
model, decoder, utils = torch.hub.load(repo_or_dir='snakers4/silero-models',
model='silero_stt',
language='ua',
device=device)
(read_batch, split_into_batches,
read_audio, prepare_model_input) = utils
def callback(_r, audio):
try:
print("Распознание ...")
with open('speech.wav', 'wb') as f:
f.write(audio.get_wav_data())
test_files = glob('speech.wav')
batches = split_into_batches(test_files, batch_size=10)
input = prepare_model_input(read_batch(batches[0]),
device=device)
output = model(input)
for example in output:
print(decoder(example.cpu()))
except sr.UnknownValueError:
print("[log] Голос не распознан!")
r = sr.Recognizer()
r.pause_threshold = 0.5
m = sr.Microphone(device_index=1)
with m as source:
r.adjust_for_ambient_noise(source)
stop_listening = r.listen_in_background(m, callback)
while True: time.sleep(0.1)
Код: Выделить всё
Warning (from warnings module):
File "C:\Users\Ukraine\AppData\Roaming\Python\Python311\site-packages\torch\hub.py", line 294
warnings.warn(
UserWarning: You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or load(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use load(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviour
Downloading: "https://github.com/snakers4/silero-models/zipball/master" to C:\Users\Ukraine/.cache\torch\hub\master.zip
0.0%
0.0%
0.0%
0.0%
0.0%
0.1%
0.1%
0.1%
0.1%
0.1%
0.1%
0.1%
0.1%
0.1%
0.1%
0.1%
0.2%
0.2%
... and more, more, more...
30.3%
30.3%
30.3%
Traceback (most recent call last):
File "C:\Users\Ukraine\Documents\pyProjects\ayko\_stt.py", line 9, in
model, decoder, utils = torch.hub.load(repo_or_dir='snakers4/silero-models',
File "C:\Users\Ukraine\AppData\Roaming\Python\Python311\site-packages\torch\hub.py", line 566, in load
model = _load_local(repo_or_dir, model, *args, **kwargs)
File "C:\Users\Ukraine\AppData\Roaming\Python\Python311\site-packages\torch\hub.py", line 595, in _load_local
model = entry(*args, **kwargs)
File "C:\Users\Ukraine/.cache\torch\hub\snakers4_silero-models_master\src\silero\silero.py", line 33, in silero_stt
model, decoder = init_jit_model(model_url=models.stt_models.get(language).get(version).get(jit_model),
File "C:\Users\Ukraine/.cache\torch\hub\snakers4_silero-models_master\src\silero\utils.py", line 130, in init_jit_model
model = torch.jit.load(model_path, map_location=device)
File "C:\Users\Ukraine\AppData\Roaming\Python\Python311\site-packages\torch\jit\_serialization.py", line 159, in load
cpp_module = torch._C.import_ir_module(cu, str(f), map_location, _extra_files, _restore_shapes) # type: ignore[call-arg]
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory
Код: Выделить всё
C:\Users\Ukraine\.cache\torch\hub\snakers4_silero-models_masterИсточник: https://stackoverflow.com/questions/781 ... t-modeling