Проблема Microsoft Custom Speech Service при использовании URL-адреса веб-сокета - PullRequest
0 голосов
/ 27 апреля 2018

совсем недавно для рабочего проекта я играл с речью на текстовые модели и, в частности, с заказной речью на текстовые модели. С помощью небольшого количества примеров смешивания и сопоставления мне удалось получить тестовое приложение для взаимодействия с обычным API Bing для преобразования речи в текст. Но когда я пытаюсь использовать его с пользовательским речевым экземпляром, работает только HTTPS URL. Когда я использую любой из доступных длинных URL-адресов веб-сокетов, возникает ошибка An unhandled exception of type 'System.NullReferenceException' occurred in SpeechClient.dll. Это небольшая проблема, поскольку эта конечная точка поддерживает только 2 минуты транскрипции, тогда как конечная точка websocket поддерживает до 10 минут.

На этой https://docs.microsoft.com/en-us/azure/cognitive-services/custom-speech-service/customspeech-how-to-topics/cognitive-services-custom-speech-use-endpoint странице я остановился. Это говорит о том, что я должен использовать URL веб-сокета при создании сервиса, но это приводит к ошибке выше.

Вот мой тестовый код для испытания:

using System;
using Microsoft.CognitiveServices.SpeechRecognition;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        DataRecognitionClient dataClient;

        static void Main(string[] args)
        {
            Program p = new Program();
            p.Run(args);
        }

        void Run(string[] args)
        {
            try
            {

                // Works
                //this.dataClient = SpeechRecognitionServiceFactory.CreateDataClient(SpeechRecognitionMode.LongDictation, "en-US", "Key");

                // Works
                //this.dataClient = SpeechRecognitionServiceFactory.CreateDataClient(SpeechRecognitionMode.LongDictation, "en-US",
                //                                                                    "Key", "Key",
                //                                                                    "https://Id.api.cris.ai/ws/cris/speech/recognize/continuous");

                // Doesn't work
                this.dataClient = SpeechRecognitionServiceFactory.CreateDataClient(SpeechRecognitionMode.LongDictation, "en-US",
                                                                                    "Key", "Key",
                                                                                    "wss://Id.api.cris.ai/ws/cris/speech/recognize/continuous");

                this.dataClient.AuthenticationUri = "https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken";

                this.dataClient.OnResponseReceived += this.ResponseHandler;
                this.dataClient.OnConversationError += this.ErrorHandler;
                this.dataClient.OnPartialResponseReceived += this.PartialHandler;

                Console.WriteLine("Starting Transcription");
                this.SendAudioHelper("Audio file path");
                (new System.Threading.ManualResetEvent(false)).WaitOne();
            } catch(Exception e)
            {
                Console.WriteLine(e);
            }

        }

        private void SendAudioHelper(string wavFileName)
        {
            using (FileStream fileStream = new FileStream(wavFileName, FileMode.Open, FileAccess.Read))
            {
                // Note for wave files, we can just send data from the file right to the server.
                // In the case you are not an audio file in wave format, and instead you have just
                // raw data (for example audio coming over bluetooth), then before sending up any 
                // audio data, you must first send up an SpeechAudioFormat descriptor to describe 
                // the layout and format of your raw audio data via DataRecognitionClient's sendAudioFormat() method.
                int bytesRead = 0;
                byte[] buffer = new byte[1024];

                try
                {
                    do
                    {
                        // Get more Audio data to send into byte buffer.
                        bytesRead = fileStream.Read(buffer, 0, buffer.Length);

                        // Send of audio data to service. 
                        this.dataClient.SendAudio(buffer, bytesRead);
                    }
                    while (bytesRead > 0);
                }
                finally
                {
                    // We are done sending audio.  Final recognition results will arrive in OnResponseReceived event call.
                    this.dataClient.EndAudio();
                }
            }
        }

        void ErrorHandler(object sender, SpeechErrorEventArgs e)
        {
            Console.WriteLine(e.SpeechErrorText);
        }

        void ResponseHandler(object sender, SpeechResponseEventArgs e)
        {
            if(e.PhraseResponse.RecognitionStatus == RecognitionStatus.EndOfDictation || e.PhraseResponse.RecognitionStatus == RecognitionStatus.DictationEndSilenceTimeout)
            {
                Console.WriteLine("Trnascription Over");
                Console.ReadKey();
                Environment.Exit(0);
            }
            for(int i = 0; i < e.PhraseResponse.Results.Length; i++)
            {
                Console.Write(e.PhraseResponse.Results[i].DisplayText);
            }
            Console.WriteLine();
        }

        void PartialHandler(object sender, PartialSpeechResponseEventArgs e)
        {

        }
    }
}

Заранее спасибо за любую помощь.

Ответы [ 2 ]

0 голосов
/ 03 июня 2018
0 голосов
/ 02 мая 2018

так что вы, вероятно, в порядке с использованием https ... мы пересматриваем SDK прямо сейчас (реструктуризация / реорганизация). Я ожидаю обновления в ближайшие пару месяцев.

Wolfgang

...