예제 #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'
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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')
예제 #6
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')
예제 #7
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)
예제 #8
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)