0
Мне не удается записать простой 3gp аудиофайл с помощью google cloud speech api. Их пример отлично работает с audio.raw, но когда я меняю его на свой файл, он идет не так.Google cloud speech транскрибирует 3gp в python
Запись сделана, как это в моем устройстве Android:
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
Я переписываю это так:
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))
Кодирование и частота дискретизации является правильным, но я получаю:
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.