I'm trying to use wit.ai to understand intent and entities in a voice command received from user in a Telegram bot.
def discover(bot, update, user_data):
voice = bot.getFile(update.message.voice.file_id)
voice.download('file.ogg')
client = Wit(wit_access_token)
with open('file.ogg', 'rb') as f:
resp = client.speech(f, True, {'Content-Type': 'audio/ogg'})
print('Yay, got Wit.ai response: ' + str(resp))
But, I'm receiving this error from Wit client:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev\pydevd.py", line 1599, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev\pydevd.py", line 1026, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/Users/PAGANEFR/PycharmProjects/MARCoBot/readaudio.py", line 8, in <module>
resp = client.speech(f, True, {'Content-Type': 'audio/ogg'})
File "C:\Python27\lib\site-packages\wit\wit.py", line 88, in speech
data=audio_file, headers=headers)
File "C:\Python27\lib\site-packages\wit\wit.py", line 41, in req
' (' + rsp.reason + ')')
wit.wit.WitError: Wit responded with status: 400 (Bad Request)
I can play ogg file with VLC. File seems consistent. I have tried to convert ogg file to wav with soundfile library:
data, samplerate = sf.read('file.ogg')
sf.write('file.wav', data, samplerate)
But I'm receiving this error:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev\pydevd.py", line 1599, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev\pydevd.py", line 1026, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/Users/PAGANEFR/PycharmProjects/MARCoBot/readaudio.py", line 6, in <module>
data = sf.read('file.ogg')
File "C:\Python27\lib\site-packages\soundfile.py", line 257, in read
subtype, endian, format, closefd) as f:
File "C:\Python27\lib\site-packages\soundfile.py", line 624, in __init__
self._file = self._open(file, mode_int, closefd)
File "C:\Python27\lib\site-packages\soundfile.py", line 1179, in _open
"Error opening {0!r}: ".format(self.name))
File "C:\Python27\lib\site-packages\soundfile.py", line 1352, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'file.ogg': File contains data in an unimplemented format.
Please help me. Thanks in advance