nikhilkumarsingh / Wit-Speech-API-Wrapper

A python client for interacting with Wit Speech Recognition API
24 stars 7 forks source link

how can I user it for persian language? #2

Closed mrmrn closed 7 years ago

mrmrn commented 7 years ago

nice work. it works very nice and the setup was very easy. thank you. but how can I use this code for persian language?

nikhilkumarsingh commented 7 years ago

You can use it for Persian language by simply changing the language in app settings to Persian. 1

mrmrn commented 7 years ago

thank you. when I set language to persian and said some thing to your code it gaved me:

Finished recording.
Traceback (most recent call last):
  File "speech_to_text.py", line 40, in <module>
    print("\nYou said: {}".format(text))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
nikhilkumarsingh commented 7 years ago

try decoding using utf-8. text = data["_text"].decode('utf8')

mrmrn commented 7 years ago

I edited https://github.com/nikhilkumarsingh/Wit-Speech-API-Wrapper/blob/master/speech_to_text.py#L32 to this: text = data["_text"].decode('utf8')

and the output is:

python speech_to_text.py
  File "speech_to_text.py", line 32
    text = data["_text"].decode('utf8')
    ^
IndentationError: unexpected indent
nikhilkumarsingh commented 7 years ago

Then correct the indentation!

mrmrn commented 7 years ago

I used python3 and it has error. I used # -*- coding: utf-8 -*- at the first and has error yet. I changed https://github.com/nikhilkumarsingh/Wit-Speech-API-Wrapper/blob/master/speech_to_text.py#L32 to text = data['_text'].decode('utf8') and it gaves me:

Traceback (most recent call last):
  File "speech_to_text.py", line 39, in <module>
    text =  RecognizeSpeech('myspeech.wav', 4)
  File "speech_to_text.py", line 32, in RecognizeSpeech
    text = data['_text'].decode('utf8')
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

and I changed https://github.com/nikhilkumarsingh/Wit-Speech-API-Wrapper/blob/master/speech_to_text.py#L40 to: print("\nYou said: {}".format(text).decode('utf8')) and it gaves:

Listening...
Finished recording.
Traceback (most recent call last):
  File "speech_to_text.py", line 40, in <module>
    print("\nYou said: {}".format(text).decode('utf8'))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
mrmrn commented 7 years ago

I used this piece of code

    text = data['_text']

    # return the text
    # return text
def read_unicode(text, charset='utf-8'):
    if isinstance(text, basestring):
        if not isinstance(text, unicode):
            text = unicode(obj, charset)
    return text

if __name__ == "__main__":
    text =  RecognizeSpeech('myspeech.wav', 4)
    print("\nYou said: {}".format(text).decode('utf8'))

and it gaves me always nothing:

reka@marn ~/D/s/Wit-Speech-API-Wrapper-master> python speech_to_text.py
ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
Listening...
Finished recording.

You said: None

I sent the .wave file to voicybot and in telegram used wit.ai as its engine and it works. but in my code it returns nothing

mrmrn commented 7 years ago

I will handle that with my preferred framework laravel. thank you for the vision you gave to me.