Ejemplo n.º 1
0
        private async Task TranslateAudioToString(IRandomAccessStream audio)
        {
            try
            {
                BingSpeechService service = new BingSpeechService(translateLanguage);
                await service.Initialization();

                TranslateResult = await service.SendAudioToAPIAsync(audio);

                var jsonResult = JsonConvert.DeserializeObject <SpeechToTextResultData>(translateResult);

                if (jsonResult.Header.Status == "success")
                {
                    TranslateResult = jsonResult.Header.Name.Trim();
                    //string keyword = jsonResult.Header.Name.Trim();
                    //MusicLuisService luisService = new MusicLuisService();

                    //TranslateResult += await luisService.InvokeAPI(keyword);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
        private async Task TranslateAudioToString(IRandomAccessStream audio)
        {
            try
            {
                BingSpeechService service = new BingSpeechService(translateLanguage, recognitionMode);
                await service.Initialization();

                var response = await service.SendAudioToAPIAsync(audio);

                var jsonResult = JsonConvert.DeserializeObject <SpeechToTextResultData>(response);

                if (jsonResult.Status == "Success")
                {
                    string resultWord = jsonResult.Results.FirstOrDefault()?.Display;

                    if (string.IsNullOrEmpty(resultWord))
                    {
                        TranslateResult += "\r\n" + "no result";
                    }
                    else
                    {
                        TranslateResult = resultWord;

                        if (IsUseLUISAPI == true)
                        {
                            MusicLuisService luisService = new MusicLuisService();
                            TranslateResult += "\r\n" + await luisService.InvokeAPI(resultWord);
                        }
                    }
                }
                else
                {
                    TranslateResult = response;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }