Exemple #1
0
def test_should_throw_language_not_implemented_error_on_handle():
    lang = Language(value='mr')
    request = SpeechRecognitionRequest(config=RecognitionConfig(language=lang))
    with pytest.raises(NotImplementedError) as e:
        handle_request(request)

    assert e.value.args[0] == 'Language not implemented yet'
Exemple #2
0
def test_should_throw_transcript_not_implemented_error_on_handle():
    request = SpeechRecognitionRequest(
        config=RecognitionConfig(transcriptionFormat='ALTERNATIVES'),
        audio=RecognitionAudio(audioUri='www.abc.com/demo.wav'))
    with pytest.raises(NotImplementedError) as e:
        handle_request(request)

    assert e.value.args[0] == 'Transcription Format not implemented yet'
Exemple #3
0
def test_should_throw_fileid_is_not_implemented_error_on_handle():
    request = SpeechRecognitionRequest(
        config=RecognitionConfig(audioFormat='MP3'),
        audio=RecognitionAudio(fileId='123'))
    with pytest.raises(NotImplementedError) as e:
        handle_request(request)

    assert e.value.args[0] == 'fileId is not implemented yet'
Exemple #4
0
def test_should_throw_empty_audio_source_is_not_implemented_error_on_handle():
    request = SpeechRecognitionRequest(config=RecognitionConfig(
        audioFormat='MP3'))
    with pytest.raises(NotImplementedError) as e:
        handle_request(request)

    assert e.value.args[
        0] == 'empty audio source is not implemented yet, send valid attributes only for audioUri or audioContent'
Exemple #5
0
def test_should_throw_audio_and_transcript_format_not_implemented_error_on_handle_ogg_srt(
):
    request = SpeechRecognitionRequest(
        config=RecognitionConfig(audioFormat='OGG', transcriptionFormat='SRT'),
        audio=RecognitionAudio(audioUri='www.abc.com/demo.wav'))
    with pytest.raises(NotImplementedError) as e:
        handle_request(request)

    assert e.value.args[0] == 'Audio Format not implemented yet'
Exemple #6
0
def test_if_given_language_not_implemented(grpc_stub, mocker):
    def handle_request(request):
        raise NotImplementedError('Language not implemented yet')

    mocker.patch('speech_recognition_service.handle_request', handle_request)
    Context = mock.MagicMock()
    mocker.patch('pytest_grpc.plugin.FakeContext', Context)
    request = SpeechRecognitionRequest()
    resp = grpc_stub.recognize(request)
    assert SpeechRecognitionResult.Status.Name(resp.status) == 'ERROR'
Exemple #7
0
def transcribe_audio_url(stub):
    language = "hi"
    url = "https://codmento.com/ekstep/test/changed.wav"
    lang = Language(value=language, name='Hindi')
    config = RecognitionConfig(language=lang,
                               audioFormat='WAV',
                               enableAutomaticPunctuation=True)
    audio = RecognitionAudio(audioUri=url)
    request = SpeechRecognitionRequest(audio=audio, config=config)

    response = stub.recognize(request)

    print(response.transcript)
Exemple #8
0
def get_srt_audio_url(stub):
    language = "hi"
    url = "https://codmento.com/ekstep/test/changed.wav"
    lang = Language(value=language, name='Hindi')
    config = RecognitionConfig(language=lang,
                               audioFormat='WAV',
                               transcriptionFormat='SRT')
    audio = RecognitionAudio(audioUri=url)
    request = SpeechRecognitionRequest(audio=audio, config=config)

    response = stub.recognize(request)

    print(response.srt)
Exemple #9
0
def get_srt_audio_bytes(stub):
    language = "hi"
    audio_bytes = read_audio()
    lang = Language(value=language, name='Hindi')
    config = RecognitionConfig(language=lang,
                               audioFormat='WAV',
                               transcriptionFormat='SRT',
                               enableInverseTextNormalization=True)
    audio = RecognitionAudio(audioContent=audio_bytes)
    request = SpeechRecognitionRequest(audio=audio, config=config)

    # creds = grpc.metadata_call_credentials(
    #     metadata_plugin=GrpcAuth('access_key')
    # )
    response = stub.recognize(request)

    print(response.srt)
Exemple #10
0
def test_if_audio_bytes_is_handled(grpc_stub, mocker):
    def save_mock(file_name, audio_data):
        return '/home/test'

    mocker.patch('os.remove')
    mocker.patch('speech_recognition_service.create_wav_file_using_bytes',
                 save_mock)

    audio_bytes = b"http://localhost/audio.mp3"
    lang = Language(value='en', name='English')
    config = RecognitionConfig(language=lang,
                               transcriptionFormat='TRANSCRIPT',
                               samplingRate='_44KHZ')
    audio = RecognitionAudio(audioContent=audio_bytes)
    request = SpeechRecognitionRequest(audio=audio, config=config)
    resp = grpc_stub.recognize(request)

    assert SpeechRecognitionResult.Status.Name(resp.status) == 'SUCCESS'
    assert resp.transcript == 'Hello world'
    os.remove.assert_called_once_with('/home/test')
Exemple #11
0
def test_if_audio_url_is_handled(grpc_stub, mocker):
    def download_mock(file_name, audio_uri):
        return '/home/test'

    mocker.patch('os.remove')
    mocker.patch('speech_recognition_service.download_from_url_to_file',
                 download_mock)

    audio_url = "http://localhost/audio.mp3"

    lang = Language(value='en', name='English')
    config = RecognitionConfig(language=lang,
                               transcriptionFormat='SRT',
                               samplingRate='_44KHZ')
    audio = RecognitionAudio(audioUri=audio_url)
    request = SpeechRecognitionRequest(audio=audio, config=config)
    resp = grpc_stub.recognize(request)
    assert SpeechRecognitionResult.Status.Name(resp.status) == 'SUCCESS'
    assert resp.srt == '1\n00:00:01,29 --> 00:00:04,88\nHello how are you\n\n'
    os.remove.assert_called_once_with('/home/test')
Exemple #12
0
def transcribe_audio_bytes(stub):
    language = "hi"
    audio_bytes = read_audio()
    lang = Language(value=language, name='Hindi')
    config = RecognitionConfig(language=lang,
                               audioFormat='MP3',
                               transcriptionFormat='TRANSCRIPT',
                               enableAutomaticPunctuation=1)
    audio = RecognitionAudio(audioContent=audio_bytes)
    request = SpeechRecognitionRequest(audio=audio, config=config)

    # creds = grpc.metadata_call_credentials(
    #     metadata_plugin=GrpcAuth('access_key')
    # )
    try:
        response = stub.recognize(request)

        print(response.transcript)
    except grpc.RpcError as e:
        e.details()
        status_code = e.code()
        print(status_code.name)
        print(status_code.value)
Exemple #13
0
def test_should_not_throw_audio_and_transcript_format_not_implemented_error_on_handle_mp3_srt(
):
    request = SpeechRecognitionRequest(
        config=RecognitionConfig(audioFormat='MP3', transcriptionFormat='SRT'),
        audio=RecognitionAudio(audioUri='www.abc.com/demo.wav'))
    handle_request(request)
Exemple #14
0
def test_should_not_throw_audio_format_not_implemented_error_on_handle_wav():
    request = SpeechRecognitionRequest(
        config=RecognitionConfig(audioFormat='WAV'),
        audio=RecognitionAudio(audioUri='www.abc.com/demo.wav'))
    handle_request(request)
Exemple #15
0
def test_should_not_throw_transcript_not_implemented_error_on_handle_transcript(
):
    request = SpeechRecognitionRequest(
        config=RecognitionConfig(transcriptionFormat='TRANSCRIPT'),
        audio=RecognitionAudio(audioUri='www.abc.com/demo.wav'))
    handle_request(request)
Exemple #16
0
def test_should_not_throw_language_not_implemented_error_on_handle():
    lang = Language(value='en')
    request = SpeechRecognitionRequest(
        config=RecognitionConfig(language=lang),
        audio=RecognitionAudio(audioUri='www.abc.com/demo.wav'))
    handle_request(request)