询问者
8.1模拟器中,new SpeechRecognizer() 法语可以,为什么日语报错?

问题
-
try { // Create an instance of SpeechRecognizer. var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer(Windows.Media.SpeechRecognition.SpeechRecognizer.SupportedGrammarLanguages.Where(i => i.LanguageTag == "ja").FirstOrDefault()); //ja//fr-FR// // Compile the dictation grammar by default. await speechRecognizer.CompileConstraintsAsync(); // Start recognition. Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync(); // Do something with the recognition result. var messageDialog = new Windows.UI.Popups.MessageDialog(speechRecognitionResult.Text, "Text spoken"); await messageDialog.ShowAsync(); } catch (Exception ex) { var messageDialogError = new Windows.UI.Popups.MessageDialog(ex.ToString(), "Error"); messageDialogError.ShowAsync(); }
//该代码运行与8.1模拟器,不能正常运行,错误信息:Exception from HRESULT: 0x800455BC
//将"ja"替换为"fr-FR"可正常运行。
//模拟器OS版本:8.10.12358.1191
不见不散
全部回复
-
你好,我分别在模拟器和真机上做了测试。模拟式和真机都是最新的版本。其中中,英,法,德,日都可以正常发音,韩语和俄语无法发音,但都没有报错。我正好在一个应用,里面用到了这个功能。
你好,我使用的是这个API:
SpeechSynthesizer speech = new SpeechSynthesizer();//实例化对象
SpeechSynthesisStream stream = await speech.SynthesizeTextToStreamAsync(voice.Tag.ToString());//将文本框的内容转化为语音流输出
if (stream != null)
{
mePlay.SetSource(stream, stream.ContentType);//将语音流设为MediaElement的源。
}www.bcmeng.com
-
感谢你的回复。
看你的示例代码,是通过文字转换为语音,没有看到以什么语言来发音。
我需要通过语音来识别输出文字。
我代码来自MSDN:http://msdn.microsoft.com/en-us/library/dn630427.aspx
不见不散
-
您确定您的模拟器和手机上有日语的识别器吗?
可以使用这段代码来实例化识别UI并定义识别器语言
SpeechRecognizerUI speechRecognizerUI = new SpeechRecognizerUI(); IEnumerable<SpeechRecognizerInformation> jaRecognizers = from recognizerInfo in InstalledSpeechRecognizers.All where recognizerInfo.Language == "jp" select recognizerInfo;
使用这个代码来判断是否存在识别器,并设定识别UI
if (jaRecognizers.Count() > 0) { //指定识别器 speechRecognizerUI.Recognizer.SetRecognizer(jaRecognizers.First()); //听写整句,基于网络识别 speechRecognizerUI.Recognizer.Grammars.AddGrammarFromPredefinedType("webSearch", SpeechPredefinedGrammar.WebSearch); //预加载全部语法 await speechRecognizerUI.Recognizer.PreloadGrammarsAsync(); // 带 UI 的语音识别器的监听页上显示的标题 speechRecognizerUI.Settings.ListenText = "正在聆听…"; // 带 UI 的语音识别器的监听页上显示的示例文本 speechRecognizerUI.Settings.ExampleText = "语音转文字"; // 是否用语音朗读识别结果 speechRecognizerUI.Settings.ReadoutEnabled = true; speechRecognizerUI.Settings.ShowConfirmation = true; try { // 开始识别 SpeechRecognitionUIResult result = await speechRecognizerUI.RecognizeWithUIAsync(); ContentBox.Text += result.RecognitionResult.Text; } catch { //错误处理 } }
希望能够帮助到您