cognitive-services-speech-sdk: SPXERR_GSTREAMER_NOT_FOUND_ERROR when using mp3 file with Microsoft.CognitiveServices.Speech

I have this piece of code throwing the error in the title:

using (var audioInput = AudioConfig.FromStreamInput(new PullAudioInputStream(new BinaryAudioStreamReader(new BinaryReader(File.OpenRead(audioFile))), AudioStreamFormat.GetCompressedFormat(AudioStreamContainerFormat.MP3))))
using (var recognizer = new SpeechRecognizer(config, sourceLanguageConfig, audioInput))

audioFile is the path to mp3 file with audio to transcribe.

I have installed the latest GStreamer gstreamer-1.0-msvc-x86_64-1.17.2.msi for Windows and added it to the User’s PATH and set GSTREAMER_ROOT_X86. That did not work.

In the docs here https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/how-to-use-codec-compressed-audio-input-streams?tabs=debian&pivots=programming-language-csharp

Handling compressed audio is implemented using GStreamer. For licensing reasons GStreamer binaries are not compiled and linked with the Speech SDK. Developers need to install several dependencies and plugins, see Installing on Windows. Gstreamer binaries need to be in the system path, so that the speech SDK can load gstreamer binaries during runtime. If speech SDK is able to find libgstreamer-1.0-0.dll during runtime it means the gstreamer binaries are in the system path.

It says it will look for libgstreamer-1.0-0.dll which is no longer included in the latest version (1.17.2) so I went back to gstreamer-1.0-x86-1.14.1 which does have the required dll, but still getting the same error.

From Visual Studio 2019 console I can invoke exe files included in that folder so I know the PATH is set correctly.

What am I missing?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

Do we have a solution yet? Speech SDK in a Azure Function. I still get the GSREMER error in the azure function.

Thanks for comments, I reopen the issue as we need to improve the documentation here

@kedzior-io, thanks, this way it works perfectly! @amitkumarshukla, this really should be documented somewhere. Playing with gstreamer and speech sdk versions is not ffun. 😃

@vortex1024

Try Microsoft.CognitiveServices.Speech version 1.13.0

Here is my working example:

Packages:

<PackageReference Include="CommandLineParser.Core" Version="1.0.1" />
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.13.0" />

Program:

using System;
using System.IO;
using CommandLineParser.Core;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using System.Threading.Tasks;
using MicrosoftSpeechSDKSamples;

namespace GetTextFromMp3
{
    internal class Program
    {
        private static async System.Threading.Tasks.Task Main(string[] args)
        {
            var parser = new FluentCommandLineParser<ApplicationArguments>();

            parser.Setup(arg => arg.File)
                .As('f', "file");

            var result = parser.Parse(args);

            if (result.HasErrors)
            {
                Console.WriteLine(result.ErrorText);
                return;
            }

            if (!File.Exists(parser.Object.File))
            {
                Console.WriteLine("Option 'f:file' error. File doesn't exist.");
                return;
            }

            var audioFile = parser.Object.File

            var textFile = Path.ChangeExtension(audioFile, "txt");
            var sourceLanguageConfig = SourceLanguageConfig.FromLanguage("es-ES");
            var config = SpeechConfig.FromSubscription("YourAzureSubscriptionKey", "EastUS");

            var stopRecognition = new TaskCompletionSource<int>();

            using (var audioInput = AudioConfig.FromStreamInput(new PullAudioInputStream(new BinaryAudioStreamReader(new BinaryReader(File.OpenRead(audioFile))), AudioStreamFormat.GetCompressedFormat(AudioStreamContainerFormat.MP3))))
            using (var recognizer = new SpeechRecognizer(config, sourceLanguageConfig, audioInput))
            {
                recognizer.Recognized += (s, e) =>
                {
                    if (e.Result.Reason == ResultReason.RecognizedSpeech)
                    {
                        Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                        File.AppendAllText(textFile, e.Result.Text + Environment.NewLine);
                    }
                    else if (e.Result.Reason == ResultReason.NoMatch)
                    {
                        Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                    }
                };

                recognizer.Canceled += (s, e) =>
                {
                    Console.WriteLine($"CANCELED: Reason={e.Reason}");

                    if (e.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }

                    stopRecognition.TrySetResult(0);
                };

                recognizer.SessionStopped += (s, e) =>
                {
                    Console.WriteLine("\n    Session stopped event.");
                    stopRecognition.TrySetResult(0);
                };

                Console.WriteLine("Recognizing text");
                await recognizer.StartContinuousRecognitionAsync();

                Task.WaitAny(new[] { stopRecognition.Task });

                await recognizer.StopContinuousRecognitionAsync();
            }
        }
    }
}

BinaryAudioStreamReader class is taken from here:

https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/csharp/sharedcontent/console/helper.cs

Run:

GetTextFromMp3 -f C:\\example.mp3

You need to set GSTREAMER_ROOT_X86_64 not GSTREAMER_ROOT_X86.

Could you try opening a new command prompt and run the following and see if you are getting a correct version. Which will help you to find if your installation path is there in the system path. gst-inspect-1.0.exe --version

Also when you are building the solution from visual studio make sure instead of anyCpu choose x64 configuration. Do let us know if that solves your problem.