alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.35k stars 1.04k forks source link

AttributeError: 'Model' object has no attribute '_handle' #1580

Closed cslop3r closed 1 month ago

cslop3r commented 1 month ago

Getting the following error but don't know how to fix it. If anyone could help me please

`vosk-model-fr-0.22.zip: 0.00B [00:00, ?B/s] Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1344, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1336, in request self._send_request(method, url, body, headers, encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1382, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1331, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1091, in _send_output self.send(msg) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1035, in send self.connect() File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1477, in connect self.sock = self._context.wrap_socket(self.sock, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py", line 455, in wrap_socket return self.sslsocket_class._create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py", line 1042, in _create self.do_handshake() File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py", line 1320, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/nathan/Documents/RSL/index.py", line 157, in model = Model(model_name="vosk-model-fr-0.22") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/vosk/init.py", line 54, in init model_path = self.get_model_path(model_name, lang) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/vosk/init.py", line 69, in get_model_path model_path = self.get_model_by_name(model_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/vosk/init.py", line 86, in get_model_by_name self.download_model(Path(directory, result_model[0])) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/vosk/init.py", line 115, in download_model urlretrieve(MODEL_PRE_URL + str(model_name.name) + ".zip", File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 240, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: ^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 215, in urlopen return opener.open(url, data, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 515, in open response = self._open(req, data) ^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 532, in _open result = self._call_chain(self.handle_open, protocol, protocol + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 492, in _call_chain result = func(*args) ^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1392, in https_open return self.do_open(http.client.HTTPSConnection, req, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1347, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)> Exception ignored in: <function Model.del at 0x152b8dd00> Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/vosk/init.py", line 60, in del _c.vosk_model_free(self._handle) ^^^^^^^^^^^^ AttributeError: 'Model' object has no attribute '_handle'`

The model is already installed and is located in my folder.

My code if it can help: with open("subs.srt", "w", encoding='utf-8') as f: print("→ Fabrication des sous-titres") SAMPLE_RATE = 16000 SetLogLevel(-1) model = Model(model_name="vosk-model-fr-0.22") rec = KaldiRecognizer(model, SAMPLE_RATE) rec.SetWords(True) with subprocess.Popen(["ffmpeg", "-loglevel", "quiet", "-i", "answer.wav", "-ar", str(SAMPLE_RATE) , "-ac", "1", "-f", "s16le", "-"], stdout=subprocess.PIPE).stdout as stream: f.write(rec.SrtResult(stream, words_per_line = 1))

nshmyrev commented 1 month ago

We had recent problem with certificate. It should work now, try again. Same as

https://github.com/alphacep/vosk-api/issues/1137

cslop3r commented 1 month ago

We had recent problem with certificate. It should work now, try again. Same as

1137

Thanks for answering. Just tested it and it still doesn't work

nshmyrev commented 1 month ago

If you want to load model from local folder you need to use model_path instead of model_name in your code

cslop3r commented 1 month ago

Thanks!

If you want to load model from local folder you need to use model_path instead of model_name in your code