speech_recognition — Speech Recognition

speech_recognition The main functionality and functions of the module

Function

speech_recognition.start(server, language)

Start the speech recognition service, parameters:

  • server - server name
  • language - Recognized language
speech_recognition.get_error_code()

Gets the error code for the resulting data. The corresponding result of the return value is as follows:

  • 0 : Right back
  • 3300:Incorrect voice input parameters
  • 3301:Voice data is not clear
  • 3302:Authentication failed
  • 3303:Raw audio or server issues
  • 3304:User request overrun (QPS)
  • 3305:User request overrun (pv-daily request volume)
  • 3307: Server side problem
  • 3308:Audio data is too long
  • 3309:Audio data anomaly
  • 3310:Audio file too large
  • 3311:Sampling rate error
  • 3312:Audio format error
  • 3333:Unknown error
  • 3334:Response timeout
speech_recognition.get_error_message()

Gets the details of the error, string type.

speech_recognition.get_result_code()

Gets the recognized result and returns an empty string if an error or timeout occurs.

speech_recognition.get_sn_code()

Get the unique identity of voice data, generated by the server system.

speech_recognition.get_all_respond()

Get the speech recognition result, including the whole reply message, such as error message, etc.

Sample Code 1:

# -*- coding: utf-8 -*-
import haloboard
import time
import event

@event.start
def use_code():
    haloboard.wifi.start(ssid = "Maker-guest", password = "makeblock", mode = haloboard.wifi.WLAN_MODE_STA)

    while(True):
        if haloboard.wifi.is_connected() == True:
            print("wifi is connected!")
            break;

    while True:
        if haloboard.button.is_pressed():
            haloboard.led.show_all(0, 0, 50)
            haloboard.speech_recognition.start(haloboard.speech_recognition.SERVER_MICROSOFT, haloboard.speech_recognition.LAN_DEFAULT, 2)
            if haloboard.speech_recognition.get_error_code() != 0:
                str = haloboard.speech_recognition.get_error_message()
                print("error_message:" + str)
            else:
                result = haloboard.speech_recognition.get_result_code()
                print("result:" + result)
                if '红色' in result:
                    haloboard.led.show_all(50, 0, 0)
                elif '黄色' in result:
                    haloboard.led.show_all(50, 50, 0)
                elif '白色' in result:
                    haloboard.led.show_all(50, 50, 50)
                elif '蓝色' in result:
                    haloboard.led.show_all(0, 0, 50)
                elif '绿色' in result:
                    haloboard.led.show_all(0, 50, 0)
                else:
                    haloboard.led.show_all(0, 0, 0)
        time.sleep(0.5)

Sample Code 2:

# -*- coding: utf-8 -*-
import haloboard
import time
import event

haloboard.speech_recognition.set_recognition_url(haloboard.speech_recognition.SERVER_MICROSOFT, "http://msapi.passport3.makeblock.com/ms/bing_speech/interactive")
haloboard.speech_recognition.set_token(haloboard.speech_recognition.SERVER_MICROSOFT, "ed8xubrmidv")
# haloboard.speech_recognition.set_account(haloboard.speech_recognition.SERVER_MICROSOFT, "embeded@makeblock.com", "123456")

@event.start
def use_code():
    haloboard.wifi.start(ssid = "Maker-guest", password = "makeblock", mode = haloboard.wifi.WLAN_MODE_STA)

    while(True):
        if haloboard.wifi.is_connected() == True:
            print("wifi is connected!")
            break;

    while True:
        if haloboard.button.is_pressed():
            haloboard.led.show_all(0, 0, 50)
            haloboard.speech_recognition.start(haloboard.speech_recognition.SERVER_MICROSOFT, haloboard.speech_recognition.LAN_DEFAULT, 2)
            if haloboard.speech_recognition.get_error_code() != 0:
                str = haloboard.speech_recognition.get_error_message()
                print("error_message:" + str)
            else:
                result = haloboard.speech_recognition.get_result_code()
                print("result:" + result)
                if '红色' in result:
                    haloboard.led.show_all(50, 0, 0)
                elif '黄色' in result:
                    haloboard.led.show_all(50, 50, 0)
                elif '白色' in result:
                    haloboard.led.show_all(50, 50, 50)
                elif '蓝色' in result:
                    haloboard.led.show_all(0, 0, 50)
                elif '绿色' in result:
                    haloboard.led.show_all(0, 50, 0)
                else:
                    haloboard.led.show_all(0, 0, 0)
        time.sleep(0.5)