def do_sphinx_speech_recognise(speech_file):
    ps.decode(audio_file=os.path.join(voice_path, speech_file),
              buffer_size=2048,
              no_search=False,
              full_utt=False)

    best_result = ps.best(count=10)
    speech = []

    for phrase in best_result:
        speech.append(phrase[0])

    if ("TURN ON THE LIGHT" in speech):
        playwave(os.path.join(voice_path, 'beep_lo.wav'))
        print("turn on the light")
        return "light on"
    elif ("TURN OFF THE LIGHT" in speech):
        playwave(os.path.join(voice_path, 'beep_lo.wav'))
        print("turn off the light")
        return "light off"
    else:
        return "null"
def do_sphinx_speech_recognise():
    for phrase in speech:
        if str(phrase) == "TURN ON THE LIGHT":
            playwave(os.path.join(voice_path, 'beep_lo.wav'))
            print("turn on the light")
            return "light on"
        elif str(phrase) == "TURN OFF THE LIGHT":
            playwave(os.path.join(voice_path, 'beep_lo.wav'))
            print("turn off the light")
            return "light off"
        else:
            playwave(os.path.join(voice_path, 'sorry.wav'))
            return "null"
def do_baidu_speech_recognise():
    result_str = get_baidu_asr()
    if result_str == "turn on the light":
        playwave(os.path.join(voice_path, 'beep_lo.wav'))
        print("turn on the light")
        return "light on"
    elif result_str == "turn off the light":
        playwave(os.path.join(voice_path, 'beep_lo.wav'))
        print("turn off the light")
        return "light off"
    else:
        playwave(os.path.join(voice_path, 'sorry.wav'))
        return "null"
              no_search=False,
              full_utt=False)

    best_result = ps.best(count=10)
    speech = []

    for phrase in best_result:
        speech.append(phrase[0])

    time.sleep(3)

    while True:
        if "HI BABY" in speech:
            print("recognise right")

        playwave(os.path.join(voice_path, 'beep_hi.wav'))

        time.sleep(3)

        net_status = is_net_ok(('www.baidu.com', 443))
        recognise_result = ""
        if net_status:
            print("######baidu recognise")
            recognise_result = do_baidu_speech_recognise("light_on.wav")
        else:
            print("######sphinx recognise")
            recognise_result = do_sphinx_speech_recognise("light_on.wav")

        print(recognise_result)
        func = switch_funcs[recognise_result]
        func()