I want AudioConfig.FromWavFileInput to accept DBCS (like Japanese) filePath RRS feed

  • Question

  • Giving DBCS (double byte character set, for example Japanese Shift_JIS) filePath to AudioConfig.FromWavFileInput seems to lead failure in Exception: System.ApplicationException: bad conversion.

    using Microsoft.CognitiveServices.Speech;
    using Microsoft.CognitiveServices.Speech.Audio;
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    namespace TestAudioConfigFromWavFileInput
        class Program
            static void Main(string[] args)
                Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
                new Program().Test();
            async void Test()
                // Creates an instance of speech config with specified subscription key and service region.
                var config = SpeechConfig.FromSubscription("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "centralus");
                var filePath = @"C:\A\日本語\full.wav"; // <-- System.ApplicationException: bad conversion
                //var filePath = @"C:\A\English\full.wav"; // <-- No problem
                // Creates a speech recognizer using file as audio input.
                // Replace with your own audio file name.
                using (var audioInput = AudioConfig.FromWavFileInput(filePath))
                    using (var recognizer = new SpeechRecognizer(config, audioInput))
                        // Performs recognition.
                        var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);
                        // Process result.
                        // ...

    Sample code from github.

    $exception+"" is

    System.ApplicationException: bad conversion
       at Microsoft.CognitiveServices.Speech.Internal.SpxExceptionThrower.ThrowIfFail(IntPtr hr)
       at Microsoft.CognitiveServices.Speech.Audio.AudioConfig.FromWavFileInput(String fileName)
       at TestAudioConfigFromWavFileInput.Program.<Test>d__1.MoveNext() in D:\Proj\TestAudioConfigFromWavFileInput\Program.cs:line 31

    I have tried ILSpy in order to trace failure point. However I have just confirmed that the error comes from BlackBox where I cannot review the code.

    [DllImport("Microsoft.CognitiveServices.Speech.core.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
    public static extern IntPtr audio_config_create_audio_input_from_wav_file_name(out IntPtr audioConfig, [MarshalAs(UnmanagedType.LPStr)] string fileName);

    Monday, June 3, 2019 5:59 AM