Beispiel #1
0
def test_set_then_get_language_code():
    from model.configuration import Configuration
    config = Configuration()
    expected = 'fr-FR'
    config.set_language_code(expected)
    result = config.get_language_code()
    assert result == expected
Beispiel #2
0
def test_str():
    from model.configuration import Configuration
    config = Configuration()
    expected_model = 'phone_call'
    expected_language_code = 'hi-IN'
    expected_use_enhanced = True
    expected_sample_rate_hertz = 48000
    expected_audio_channel_count = 5
    expected_enable_separate_recognition_per_channel = False
    expected_boost = 6
    expected_phrases = ['testing', '$ADDRESSNUM']
    config.set_model(expected_model)
    config.set_language_code(expected_language_code)
    config.set_enable_separate_recognition_per_channel(
        expected_enable_separate_recognition_per_channel)
    config.set_audio_channel_count(expected_audio_channel_count)
    config.set_use_enhanced(expected_use_enhanced)
    config.set_sample_rate_hertz(expected_sample_rate_hertz)
    config.set_speech_context(expected_phrases, expected_boost)
    result = config.__str__()
    assert isinstance(result, str)
    assert expected_model in result
    assert expected_language_code in result
    assert str(expected_use_enhanced) in result
    assert str(expected_sample_rate_hertz) in result
    assert str(expected_audio_channel_count) in result
    assert str(expected_enable_separate_recognition_per_channel) in result
    assert str(expected_boost) in result
def test_get_hypothesis():
    from model.configuration import Configuration
    from utilities.speech_to_text import SpeechToText
    uri = 'gs://brb/test_audio_n_truth/1.wav'
    configuration_object = Configuration()
    configuration_object.set_language_code('en-US')
    configuration_object.set_encoding('LINEAR16')
    configuration_object.set_sample_rate_hertz(44100)
    configuration_object.set_model('default')
    speech = SpeechToText()
    result = speech.get_hypothesis(uri, configuration_object)
    expected = ' testing 1 2 3  hello hello testing one two three'
    assert result == expected
Beispiel #4
0
def test_create_unique_root_2():
    from utilities.utilities import Utilities
    from model.configuration import Configuration
    from model.nlp import NLPModel
    u = Utilities()
    configuration = Configuration()
    nlp_model = NLPModel()
    root = '12345'
    configuration.set_model('video')
    configuration.set_use_enhanced(False)
    configuration.set_language_code('fr_FR')
    configuration.set_alternative_language_codes(['en-US', 'ru-RU'])
    configuration.set_speech_context('hi', 5)
    nlp_model.set_remove_stop_words(True)
    nlp_model.set_apply_stemming(False)
    nlp_model.set_expand_contractions(True)
    nlp_model.set_n2w(True)
    result = u.create_unique_root(root, configuration, nlp_model)
    expected = '12345_video_fr_FR_alts_applied_speech_adaptation_applied_boost_5_stop_words_removed_contractions_expanded_numbers_converted_2_words'
    assert result == expected
def test_update_csv():
    from utilities.io_handler import IOHandler
    from model.configuration import Configuration
    from model.nlp import NLPModel
    import os
    configuration = Configuration()
    nlp_model = NLPModel()
    io = IOHandler()
    result_file_name = io._result_file_name
    io.set_result_path('test_results_path')
    io.write_csv_header()
    expected_uri = 'gs://foo/bar/baz/test.flac'
    expected_lang = 'fr-FR'
    nlp_model.set_apply_stemming(True)
    configuration.set_language_code(expected_lang)
    io.update_csv(expected_uri, configuration, nlp_model)
    full_path = f'{io.get_result_path()}/{result_file_name}'

    with open(full_path, 'r') as file:
        contents = file.read()
        os.remove(full_path)
        assert expected_uri in contents
        assert expected_lang in contents
        assert 'True' in contents
                                string = f'Running with phrase hints, boost {boost}'
                            else:
                                string = 'No speech context applied'
                            print(string)
                            logger.debug(string)
                            if phrases:
                                configuration.set_speech_context(phrases, boost)
                            else:
                                configuration.set_speech_context([], 0)
                            if alt_run:
                                configuration.set_alternative_language_codes(alternative_language_codes)
                          

                            configuration.set_model(model)
                            configuration.set_sample_rate_hertz(sample_rate_hertz)
                            configuration.set_language_code(language)
                            configuration.set_encoding(encoding)
                            if audio_channel_count > 1:
                                configuration.set_audio_channel_count(audio_channel_count)
                                configuration.set_enable_separate_recognition_per_channel(True)

                            logger.debug(f'CONFIGURATION: {configuration}')
                            print(f'STARTING')
                            msg = f'audio: {audio}, {configuration}'
                            logger.debug(msg)
                            print(msg)



                            # Generate hyp
                            speech_to_text = SpeechToText()
Beispiel #7
0
def test_set_language_code():
    from model.configuration import Configuration
    config = Configuration()
    config.set_language_code('en-US')