Reputation: 207
I have successfully transcribed a audio file with the google Speech-to-Text API from my code when I used fetchFromUri like this code:
var file = RecognitionAudio.fetchFromUri(fileUri);
var longRunningRecognizeOperation = speech.LongRunningRecognize(config, file);
and also when is use fetchFromStorageUri like this:
var storageFile = RecognitionAudio.fetchFromStorageUri(gsStorageUri);
var longRunningRecognizeOperation = speech.LongRunningRecognize(config, storageFile);
But as soon I try to use it with fromStream
var audioStream = RecognitionAudio.fromStream(fileStream);
var longRunningRecognizeOperation = speech.LongRunningRecognize(config, audioStream);
I got the error
"The caller does not have permission"
We use a service account key json in our project but it seems that we have t o configure some permission to get RecognitionAudio.fromStream
work.
Does anyone know what to do? :)
Upvotes: 1
Views: 229
Reputation: 207
The error message was misleading as it did indicate a permission issue. Instead, the error was related to the stream. However, I was able to resolve the issue by converting the stream into a ByteArray.
Like this:
using (MemoryStream memoryStream = new MemoryStream())
{
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(memoryStream);
var audioByteArray = memoryStream.ToArray();
RecognitionAudio recognitionAudio = RecognitionAudio.FromBytes(audioByteArray);
var longRunningRecognizeOperation = speech.LongRunningRecognize(googleTranscriptionConfig, recognitionAudio);
longRunningRecognizeOperation = longRunningRecognizeOperation.PollUntilCompleted();
var response = longRunningRecognizeOperation.Result;
return response;
}
Upvotes: 0