Thank you for fixing the tab/space indentation problems, it’s working now.
I’ve tested the new try/except mechanism:
-
invalid configuration options for google: works, the error “An error was encountered when transcribing: 400 Invalid recognition ‘config’: The phone_call model is currently not supported for language : de-DE.” was correctly embedded in the voicemail as text.
-
google server not responding (to simulate this, I added 8.8.8.8 accounts.google.com oauth2.googleapis.com www.googleapis.com to the /etc/hosts file) => took a long time, but error was properly embedded in the voicemail message and the message was correctly delivered: “An error was encountered when transcribing: Deadline of 5000.0s exceeded while calling functools.partial(<function _wrap_stream_errors..error_remapped_callable”
So far, so good, however:
- invalid json file specified in configuration: doesn’t work, voicemail is lost. When manually processing the voicemail, sttparse crashes this way:
[root@freepbx bin]# cat “/admin/VoiceMail-processing/FreePBX-VM-Transcription-21-06-14 16:15.log” | sttparse
Traceback (most recent call last):
File “/usr/local/bin/sttparse”, line 159, in
sys.exit(main())
File “/usr/local/bin/sttparse”, line 124, in main
speech = speechrec(waveobj)
File “/usr/local/bin/sttparse”, line 31, in speechrec
client = speech.SpeechClient.from_service_account_json(globalconfig(‘creds_file’))
File “/usr/lib/python3.6/site-packages/google/cloud/speech_v1/services/speech/client.py”, line 152, in from_service_account_file
credentials = service_account.Credentials.from_service_account_file(filename)
File “/usr/lib/python3.6/site-packages/google/oauth2/service_account.py”, line 234, in from_service_account_file
filename, require=[“client_email”, “token_uri”]
File “/usr/lib/python3.6/site-packages/google/auth/_service_account_info.py”, line 72, in from_filename
with io.open(filename, “r”, encoding=“utf-8”) as json_file:
FileNotFoundError: [Errno 2] No such file or directory: ‘/usr/local/etc/vmtranscibe-316511-8af2e892f278.json2’
- invalid contents of the json file (i changed a single character in the key from 0 to 1) => Voicemail is lost and never arrives
[root@freepbx bin]# cat “/admin/VoiceMail-processing/FreePBX-VM-Transcription-21-06-14 16:15.log” | sttparse
Traceback (most recent call last):
File “/usr/local/bin/sttparse”, line 159, in
sys.exit(main())
File “/usr/local/bin/sttparse”, line 124, in main
speech = speechrec(waveobj)
File “/usr/local/bin/sttparse”, line 31, in speechrec
client = speech.SpeechClient.from_service_account_json(globalconfig(‘creds_file’))
File “/usr/lib/python3.6/site-packages/google/cloud/speech_v1/services/speech/client.py”, line 152, in from_service_account_file
credentials = service_account.Credentials.from_service_account_file(filename)
File “/usr/lib/python3.6/site-packages/google/oauth2/service_account.py”, line 234, in from_service_account_file
filename, require=[“client_email”, “token_uri”]
File “/usr/lib/python3.6/site-packages/google/auth/_service_account_info.py”, line 74, in from_filename
return data, from_dict(data, require=require)
File “/usr/lib/python3.6/site-packages/google/auth/_service_account_info.py”, line 55, in from_dict
signer = crypt.RSASigner.from_service_account_info(data)
File “/usr/lib/python3.6/site-packages/google/auth/crypt/base.py”, line 114, in from_service_account_info
info[_JSON_FILE_PRIVATE_KEY], info.get(_JSON_FILE_PRIVATE_KEY_ID)
File “/usr/lib/python3.6/site-packages/google/auth/crypt/_cryptography_rsa.py”, line 134, in from_string
key, password=None, backend=_BACKEND
File “/usr/lib64/python3.6/site-packages/cryptography/hazmat/primitives/serialization.py”, line 20, in load_pem_private_key
return backend.load_pem_private_key(data, password)
File “/usr/lib64/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1006, in load_pem_private_key
password,
File “/usr/lib64/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1225, in _load_key
self._handle_key_loading_error()
File “/usr/lib64/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1275, in _handle_key_loading_error
raise ValueError(“Unsupported public key algorithm.”)
ValueError: Unsupported public key algorithm.
So it currently correctly catches the specific reason of a google server responding with an error and the google server not responding at all, but not an incorrect json configuration file, incorrect json authdata in the file… If you have time for further reliability improvements, this would be much appreciated. Perhaps there could some very generic error handling, so whatever the error was, at least the voicemail continues to be delivered? I don’t know if in python you can catch those generic Traceback messages and just embed them as transcribed text - that’s how I would approach it in C#.