Ejemplo n.º 1
0
def initialise():
    # Initialise the speech recognition engine and the iCub controller
    my_speech = SpeechRecognizer(
        hmm_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/model/en-us/en-us",
        language_model_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/model/en-us/en-us.lm.bin",
        dictionary_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/data/icub.dic",
        grammar_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/data/icub.gram",
        rule_name='icub.basicCmd',
        fsg_name="icub")
    # iCub initialization
    my_icub = iCub(icub_root='/icubSim')
    # Load acapela configuration from file
    my_icub.set_acapela_credential("./acapela_config.csv")
    account_login, application_login, application_password, service_url = my_icub.get_acapela_credential(
    )
    print("[ACAPELA]Acapela configuration parameters:")
    print("Account Login: "******"Application Login: "******"Account Password: "******"Service URL: " + str(service_url))
    print("")
    # Return the objects
    return my_speech, my_icub
Ejemplo n.º 2
0
def test(dirs):
    print('Testing on {0}'.format(dirs))
    print('Loading recognizer, please wait...')
    speech_recognizer = SpeechRecognizer(DICTIONARY)
    print('Loading completed.')
    all = 0
    correct = 0
    for i, dir in enumerate(dirs):
        curr_all = 0
        curr_correct = 0
        for file in os.walk(DIR_NAME + '/' + dir).next()[2]:
            expected_word = file.split('_')[0]
            if not filter(expected_word):
                continue
            rate, samples = wavfile.read('{0}/{1}/{2}'.format(
                DIR_NAME, dir, file))
            rate, speech_words = extract_words(rate, samples, 1)
            if len(speech_words) != 1:
                print('Error extracting {0}/{1}'.format(dir, file))
                continue
            word, _ = try_recognition(rate, speech_words[0], speech_recognizer)
            all += 1
            curr_all += 1
            if word == expected_word:
                correct += 1
                curr_correct += 1
            else:
                print 'Expected {0}, got {1}'.format(expected_word, word)
        if curr_all > 0:
            print('Correct {0}% in {1}'.format(100.0 * curr_correct / curr_all,
                                               dir))
        print('Completed {0}%'.format(100.0 * (i + 1) / float(len(dirs))))
    print('--------------------------------')
    print('Correct {0}%'.format(100.0 * correct / all))
    print('Done testing.')
Ejemplo n.º 3
0
def test(evaluation):
    print('Loading recognizer, please wait...')
    speech_recognizer = SpeechRecognizer('../dictionary/')
    print('Loading completed.')
    n = len(evaluation['test'])
    all = 0
    correct = 0
    for i, example in enumerate(evaluation['test']):
        curr_all = 0
        curr_correct = 0
        example_name = example['file']
        hint = example['expected_words_count']
        rate, samples = wavfile.read('../wav/{0}.wav'.format(example_name))
        rate, speech_words = extract_words(rate, samples, hint)
        if len(speech_words) != len(example['words']):
            print('Error in extracting words. Skipping {0}.'.format(
                example_name))
            continue
        for word, sol_word in zip(speech_words, example['words']):
            sol, _ = try_recognition(rate, word, speech_recognizer)
            #print('Expected {0}, recognized {1}'.format(sol_word, sol))
            all += 1
            curr_all += 1
            if sol == sol_word:
                correct += 1
                curr_correct += 1
        print('Completed {0}%'.format(100.0 * (i + 1) / float(n)))
        print('Stats on {0}, correct {1}%'.format(
            example_name, 100.0 * curr_correct / curr_all))
        break
    print('--------------------------------------')
    print('Correct {0}%'.format(100.0 * correct / all))
Ejemplo n.º 4
0
def initialise(root='/icubSim'):
    # Initialise the speech recognition engine and the iCub controller
    my_speech = SpeechRecognizer(hmm_path=HMM_PATH,
                                 language_model_path=LANGUAGE_MODEL_PATH,
                                 dictionary_path=DICTIONARY_PATH,
                                 grammar_path=GRAMMAR_PATH,
                                 rule_name='icub.basicCmd',
                                 fsg_name="icub")
    # iCub initialization
    my_icub = iCub(icub_root=root)
    # Load acapela configuration from file
    my_icub.set_acapela_credential(ACAPELA_CSV)
    account_login, application_login, application_password, service_url = my_icub.get_acapela_credential(
    )
    print("[ACAPELA]Acapela configuration parameters:")
    print("Account Login: "******"Application Login: "******"Account Password: "******"Service URL: " + str(service_url))
    print("")
    # Return the objects
    return my_speech, my_icub
Ejemplo n.º 5
0
def initialise(objects_path):
    # Initialise the speech recognition engine and the iCub controller
    my_speech = SpeechRecognizer(
        hmm_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/model/en-us/en-us",
        language_model_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/model/en-us/en-us.lm.bin",
        dictionary_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/data/icub.dic",
        grammar_path=
        "/home/massimiliano/pyERA/examples/ex_icub_trust_cognitive_architecture/sphinx/data/icub.gram",
        rule_name='icub.basicCmd',
        fsg_name="icub")
    # iCub initialization
    my_icub = iCub(icub_root='/icubSim')
    # Load acapela configuration from file
    my_icub.set_acapela_credential("./acapela_config.csv")
    account_login, application_login, application_password, service_url = my_icub.get_acapela_credential(
    )
    print("[ACAPELA]Acapela configuration parameters:")
    print("Account Login: "******"Application Login: "******"Account Password: "******"Service URL: " + str(service_url))
    print("")
    #If there are images of template stored in the folder,
    #it opens the folder and load the objects in memory.
    print("[STATE init] loading objects from memory...")
    for file in os.listdir(objects_path):
        if file.endswith(".png"):
            object_name = os.path.splitext(file)[0]
            print("Object name: " + object_name)
            print("Object path: " + os.path.join(objects_path, file))
            template = cv2.imread(os.path.join(objects_path, file))
            my_icub.learn_object_from_histogram(template, object_name)
    # Return the objects
    return my_speech, my_icub
Ejemplo n.º 6
0
import sys

from speech_recognition import SpeechRecognizer

if __name__ == '__main__':
    try:
        recog = SpeechRecognizer()
    except SpeechRecognizer.InvalidDevice as e:
        print(e.message)
        sys.exit(1)
Ejemplo n.º 7
0
def main():
    warnings.simplefilter('ignore')
    clear_tmp()
    print('0. Simplified')
    print('1. Full')
    option = input('Select input: ')
    if option == 0:
        dir = 'simplified_dict/'
    else:
        dir = 'dictionary/'
    print('Loading recognizer, please wait...')
    speech_recognizer = SpeechRecognizer(dir)
    print('Loading completed.')
    print('0. Record new')
    print('1. Use existing wav file (from wav/)')
    print('2. Just record wav for later use')
    print('3. Split existing file (from wav/)')
    option = input('Select input: ')
    if option == 0:
        speech_file = record_wav()
    elif option == 1:
        speech_file = raw_input('File name (without .wav): ')
    elif option == 2:
        _ = record_wav()
        return
    elif option == 3:
        speech_file = raw_input('File name (without .wav): ')
        hint = input(
                'Hint maybe (enter expected number of words, 0 for no hint)? ')
        rate, samples = wavfile.read('wav/{0}.wav'.format(speech_file))
        rate, speech_words = extract_words(rate, samples, hint)
        for speech in speech_words:
            _ = save_tmp_wav(rate, speech)
        print('Extracted {0} words'.format(len(speech_words)))
        return
    else:
        print('Invalid option')
        return
    hint = input('Hint maybe (enter expected number of words, 0 for no hint)? ')
    rate, samples = wavfile.read('wav/{0}.wav'.format(speech_file))
    rate, speech_words = extract_words(rate, samples, hint)
    print('Extracted {0}'.format(len(speech_words)))
    correct_count = 0
    count = 0
    for speech in speech_words:
        speech_copy = speech[:]
        _ = raw_input('Press enter to continue...')
        wav_name = save_tmp_wav(rate, speech)
        play_wav('tmp/{0}'.format(wav_name))
        word, confidence = try_recognition(rate, speech_copy, speech_recognizer)
        print('Recognized [{0}] with confidence {1}'.format(word, confidence))
        count += 1
        correct = input('Is it correct (0/1)? ')
        if correct == 0:
            add = input('Do you want to add this word in dictionary (0/1)? ')
            if add == 0:
                print(':(')
            else:
                text_word = raw_input('Write string representation: ')
                text_word.rstrip('\n').replace(' ', '_')
                save_wav(text_word, wav_name, rate, speech)
                print('Added new word [{0}]'.format(text_word))
        else:
            correct_count += 1
            os.rename('tmp/{0}'.format(wav_name), 'tmp/{0}.wav'.format(word))
            print(':)')
    print('Recognized {0}% correctly.'.format(
            100.0 * float(correct_count) / float(count)))