Wit AI speech recognition python

197 views Asked by At

The code i wrote does not give the answer i want.

from wit import Wit

client = Wit("XXXYYYZZZ")

with open('sa.mp3', 'rb') as f:
  resp = client.speech(f, {'Content-Type': 'audio/wav'})
print('Yay, got Wit.ai response: ' + str(resp))`

the code gives me the "Yay, got Wit.ai response: {'entities': {}, 'intents': [], 'text': '', 'traits': {}}"

why?

1

There are 1 answers

1
iohans On BEST ANSWER

The most likely reason for your errored response is that you are sending the wrong format to Wit. Either change the format of the file to something like sa.wav or change the Content-Type to audio/mpeg.

  • PCM (audio/raw) Default format.
  • mp3 (audio/mpeg)
  • wav (audio/wav)
from wit import Wit

client = Wit("XXXYYYZZZ")

with open('sa.mp3', 'rb') as f:
  resp = client.speech(f, {'Content-Type': 'audio/mpeg'})
print('Yay, got Wit.ai response: ' + str(resp))

Docs: https://wit.ai/docs/http/20221114/