Skip to content

transcribe 3gp audio #816

@ghost

Description

I cannot manage to transcribe a simple 3gp audio file with the google cloud speech api. Your example is running fine with audio.raw but when I change it to my file it goes wrong.

Recording is made like this in my android device:

 mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);

I transcribe it like this:

import io
import os

# Imports the Google Cloud client library
from google.cloud import speech

# Instantiates a client
speech_client = speech.Client()

# The name of the audio file to transcribe
file_name = os.path.join(
    os.path.dirname(__file__),
    'resources',
    'phone.3gp')

# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file:
    content = audio_file.read()
    audio_sample = speech_client.sample(
        content,
        source_uri=None,
        encoding='AMR',
        sample_rate=8000) #LINEAR16

# Detects speech in the audio file
alternatives = speech_client.speech_api.sync_recognize(audio_sample)

for alternative in alternatives:
    print('Transcript: {}'.format(alternative.transcript))

Encoding and sample rate is correct but I get:

Traceback (most recent call last):
  File "transcribe.py", line 26, in <module>
    alternatives = speech_client.speech_api.sync_recognize(audio_sample)
  File "C:\Program Files\Anaconda2\lib\site-packages\google\cloud\speech\_gax.py", line 266, in sync_recognize
    raise ValueError('More than one result or none returned from API.')
ValueError: More than one result or none returned from API.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions