public CodewordSpeechRecognizer(string Codeword, IReadOnlyList <AllJoynAction> Actions) { var en_us = new Windows.Globalization.Language("en-US"); SpeechRecognizer = new SpeechRecognizer(en_us); Logger.LogInfo("Recognizing in " + SpeechRecognizer.CurrentLanguage.NativeName); // Prepend the codeword to all commands. foreach (AllJoynAction action in Actions) { SpeechRecognizer.Constraints.Add( new SpeechRecognitionListConstraint( action.Commands.Select( x => Codeword + ", " + x ), action.Id ) ); } SpeechRecognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout = new TimeSpan(1, 0, 0); Logger.LogInfo("Timeout: " + SpeechRecognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout); SpeechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated; SpeechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed; }
public void RecordSpeachToText() { Task.Factory.StartNew(async() => { try { var language = new Windows.Globalization.Language("en-US"); var speechRecognizer = new SpeechRecognizer(language); await speechRecognizer.CompileConstraintsAsync(); var result = await speechRecognizer.RecognizeWithUIAsync(); Recorded?.Invoke(result.Text); } catch (System.Runtime.InteropServices.COMException) { Device.BeginInvokeOnMainThread(async() => { var messageDialog = new Windows.UI.Popups.MessageDialog("Please download en-US Language-Pack", "Language not found"); await messageDialog.ShowAsync(); Recorded?.Invoke(""); }); } catch { Device.BeginInvokeOnMainThread(async() => { var messageDialog = new Windows.UI.Popups.MessageDialog("No permission to record", "Permission denied"); await messageDialog.ShowAsync(); Recorded?.Invoke(""); }); } }); }
public object Convert(object value, Type targetType, object parameter, string language) { if (value is string) { bool isNativeName = false; if (parameter is string) { bool.TryParse(parameter as string, out isNativeName); } string name = string.Empty; string threeLetterCode = value as string; var twoLetterCode = LanguageCodeHelper.GetTwoLetterCode(threeLetterCode); if (twoLetterCode != null && twoLetterCode.Length == 2) { var lang = new Windows.Globalization.Language(twoLetterCode); name = isNativeName ? lang.NativeName : lang.DisplayName; } else { name = threeLetterCode; if (string.IsNullOrEmpty(name)) { name = "Unknown"; } } return(name); } return(value); }
protected override void OnNavigatedTo(NavigationEventArgs e) { LanguageValues = new List<LanguageValue>(); // First show the default setting // LanguageValues.Add(new LanguageValue() { DisplayName = "Use language preferences (recommended)", LanguageTag = "" }); // If there are app languages that the user speaks, show them next // Note: the first (non-override) language, if set as the primary language override // would give the same result as not having any primary language override. There's // still a difference, though: If the user changes their language preferences, the // default setting (no override) would mean that the actual primary app language // could change. But if it's set as an override, then it will remain the primary // app language after the user changes their language preferences. // Add machine preferred languages /* for (var i = 0; i < Windows.Globalization.ApplicationLanguages.Languages.Count; i++) { var lang = new Windows.Globalization.Language(Windows.Globalization.ApplicationLanguages.Languages[i]); LanguageValues.Add(new LanguageValue() { DisplayName = lang.NativeName, LanguageTag = lang.LanguageTag }); }*/ // Add application manifest languages for (var i = 0; i < Windows.Globalization.ApplicationLanguages.ManifestLanguages.Count; i++) { var lang = new Windows.Globalization.Language(Windows.Globalization.ApplicationLanguages.ManifestLanguages[i]); LanguageValues.Add(new LanguageValue() { DisplayName = lang.NativeName, LanguageTag = lang.LanguageTag }); } MachineLanguages.Text = GetAppLanguagesAsFormattedString(Windows.Globalization.ApplicationLanguages.Languages); ManifestLanguages.Text = GetAppLanguagesAsFormattedString(Windows.Globalization.ApplicationLanguages.ManifestLanguages); int selectIndex = -1; int index = 0; foreach (var l in LanguageValues) { LanguageCombo.Items.Add(l); if (FindCurrent(l) == true) selectIndex = index; index++; } if (LanguageCombo.Items.Count > 0) { if (selectIndex != -1) LanguageCombo.SelectedIndex = selectIndex; else // if PrimaryLanguageOverride not set, select first language in the list LanguageCombo.SelectedIndex = 0; } lastSelectionIndex = LanguageCombo.SelectedIndex; LanguageCombo.SelectionChanged += LanguageCombo_SelectionChanged; var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); this.AppDescription.Text = resourceLoader.GetString("appDescription"); }
protected WinSpeechRecognizer Create(CultureInfo?culture) { if (culture == null) { return(new WinSpeechRecognizer()); } var lang = new Windows.Globalization.Language(culture.Name); return(new WinSpeechRecognizer(lang)); }
public async Task <bool> InitializeRecognizerAsync() { Debug.WriteLine("[Speech to Text]: initializing Speech Recognizer..."); var language = new Windows.Globalization.Language(_languageName); _recognizer = new SpeechRecognizer(language); // Set timeout settings. _recognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(_recognizerInitialSilenceTimeOutInSeconds); _recognizer.Timeouts.BabbleTimeout = TimeSpan.FromSeconds(_recognizerBabbleTimeoutInSeconds); _recognizer.Timeouts.EndSilenceTimeout = TimeSpan.FromSeconds(_recognizerEndSilenceTimeoutInSeconds); // Set UI text _recognizer.UIOptions.AudiblePrompt = "Say what you want to do..."; if (!this.IsOffline()) { // This requires internet connection SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development"); _recognizer.Constraints.Add(topicConstraint); } else { // In case of network issue string[] responses = { "I would like to rent a bike", "I want to rent a bike", "I'd like to rent a bike", "rent a bike", "I would like to rent a bicycle", "I want to rent a bicycle", "I'd like to rent a bicycle", "rent a bicycle" }; // Add a list constraint to the recognizer. var listConstraint = new SpeechRecognitionListConstraint(responses, "rentBikePhrases"); _recognizer.Constraints.Add(listConstraint); } SpeechRecognitionCompilationResult result = await _recognizer.CompileConstraintsAsync(); // Required if (result.Status != SpeechRecognitionResultStatus.Success) { Debug.WriteLine("[Speech to Text]: Grammar Compilation Failed: " + result.Status.ToString()); return(false); } _recognizer.HypothesisGenerated += Recognizer_HypothesisGenerated; _recognizer.StateChanged += Recognizer_StateChanged; _recognizer.ContinuousRecognitionSession.ResultGenerated += (s, e) => { Debug.WriteLine($"[Speech to Text]: recognizer results: {e.Result.Text}, {e.Result.RawConfidence.ToString()}, {e.Result.Confidence.ToString()}"); }; Debug.WriteLine("[Speech to Text]: done initializing Speech Recognizer"); return(true); }
public async Task <OcrResult> RecognizeText(Bitmap bmp) { var sbmp = await ConvertToSoftwareBitmap(bmp); Windows.Globalization.Language language = new Windows.Globalization.Language("en"); OcrEngine ocrEngine = OcrEngine.TryCreateFromLanguage(language); //OcrEngine ocrEngine = OcrEngine.TryCreateFromUserProfileLanguages(); var ocrResult = await ocrEngine.RecognizeAsync(sbmp); return(ocrResult); }
public void SetOcrLanguage(string language) { OcrLanguages langus = new OcrLanguages(); string tag = langus.GetTag(language); ocrLanguage = new UwpLanguage(tag); engine = UwpOcrEngine.TryCreateFromLanguage(ocrLanguage); if (engine == null) { ocrLanguage = null; throw new InvalidOperationException(errMsgFailedToSetLanguage); } }
public WindowsOCR() { // Engine を既定の言語で初期化する。 engine = UwpOcrEngine.TryCreateFromUserProfileLanguages(); if (engine == null) { throw new InvalidOperationException(errMsgFailedToConstract); } // Propertyの初期化 ocrLanguage = new UwpLanguage(engine.RecognizerLanguage.LanguageTag); ocrAngle = 0.0; ocrResults = new List <WinOcrResult>(); }
public async void StartRecognizing_Click(object sender, RoutedEventArgs e) { // Create an instance of SpeechRecognizer. var language = new Windows.Globalization.Language("en-US"); var speechRecognizer = new SpeechRecognizer(language); // Compile the dictation grammar by default. await speechRecognizer.CompileConstraintsAsync(); // Start recognition. SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync(); // Pass recognized text to LUIS CallLUISService(speechRecognitionResult.Text); }
/* * IMEが切り替えられた。 */ private void TextServiceManager_InputLanguageChanged(CoreTextServicesManager sender, object ev) { Debug.Write("<<--- InputLanguageChanged"); // IMEの名前を得ます。 Windows.Globalization.Language lng = sender.InputLanguage; if (lng != null) { Debug.Write(" Lang:{0}", lng.DisplayName); } Debug.WriteLine(""); // editContextを作り直します。 UpdateEditContext(); }
private async void btnSearch_Click(object sender, RoutedEventArgs e) { this.txtCortanaMessages.Text = "Je vous écoute..."; Windows.Globalization.Language langFR = new Windows.Globalization.Language("fr-FR"); SpeechRecognizer recognizer = new SpeechRecognizer(langFR); SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development"); recognizer.Constraints.Add(topicConstraint); await recognizer.CompileConstraintsAsync(); // Required var recognition = recognizer.RecognizeAsync(); recognition.Completed += this.Recognition_Completed; }
private async void listenButton_Click(object sender, RoutedEventArgs e) { var language = new Windows.Globalization.Language("en-US"); var recognizer = new SpeechRecognizer(language); await recognizer.CompileConstraintsAsync(); recognizer.UIOptions.IsReadBackEnabled = false; recognizer.UIOptions.ShowConfirmation = false; recognizer.UIOptions.AudiblePrompt = "Say something"; SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync(); //SpeechRecognitionResult result = await recognizer.RecognizeAsync(); if (result.Status == SpeechRecognitionResultStatus.Success && result.Text.Length > 0) { results.Add(result); readText(result.Text); } }
private async void comboBox_Language_SelectedIndexChanged(object sender, EventArgs e) { ClearResult(0); m_language = new Windows.Globalization.Language(m_ro_listLanguage[comboBox_Language.SelectedIndex].LanguageTag); if (!OcrEngine.IsLanguageSupported(m_language)) { MessageBox.Show(string.Format("'{0}' is not supported in this system!", m_language.DisplayName), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (m_bitmap != null) { await ImageToText(m_memoryStream); } } }
internal AdaptiveCaptionStream(IManifestStream manifestStream) { ManifestStream = manifestStream; Name = manifestStream.Name; Language = manifestStream.Language; if (string.IsNullOrEmpty(Name)) { if (!string.IsNullOrEmpty(Language)) { var name = new Windows.Globalization.Language(manifestStream.Language).DisplayName; if (!string.IsNullOrEmpty(name)) { name = manifestStream.Language; } Name = name; } } }
private async void Button_OnClick(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.FileTypeFilter.Add(".png"); // 选择文件 var imgFile = await picker.PickSingleFileAsync(); if (imgFile != null) { using (var inStream = await imgFile.OpenReadAsync()) { // 解码图片 var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(Windows.Graphics.Imaging.BitmapDecoder.PngDecoderId, inStream); // 获取图像 var swbmp = await decoder.GetSoftwareBitmapAsync(); // 准备识别 Windows.Globalization.Language lang = new Windows.Globalization.Language("zh-CN"); // 判断是否支持简体中文识别 if (Windows.Media.Ocr.OcrEngine.IsLanguageSupported(lang)) { var engine = Windows.Media.Ocr.OcrEngine.TryCreateFromLanguage(lang); if (engine != null) { var result = await engine.RecognizeAsync(swbmp); if (result != null) { var dialog = new Windows.UI.Popups.MessageDialog($"识别内容 {result.Text}"); await dialog.ShowAsync(); } } } else { var dialog = new Windows.UI.Popups.MessageDialog("不支持简体中文的识别。"); await dialog.ShowAsync(); } } } }
private async void Init(Windows.Globalization.Language language) { ListenButton.IsEnabled = false; bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission(); if (!permissionGained) { MessageDialog("Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone."); } var recognizer = new SpeechRecognizer(language); var topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development"); recognizer.Constraints.Add(topicConstraint); var compilationResult = await recognizer.CompileConstraintsAsync(); _SpeechRecognizer = recognizer; ListenButton.IsEnabled = true; }
internal AdaptiveAudioStream(IManifestStream manifestStream) { ManifestStream = manifestStream; Name = manifestStream.Language; Language = manifestStream.Language; if (string.IsNullOrEmpty(manifestStream.Name)) { if (!string.IsNullOrEmpty(manifestStream.Language)) { var name = new Windows.Globalization.Language(manifestStream.Language).DisplayName; if (!string.IsNullOrEmpty(name)) { name = manifestStream.Language; } Name = name; } } }
public static bool Lang(string lang) { try { var langtag = new Windows.Globalization.Language(lang); if (!OcrEngine.IsLanguageSupported(langtag)) { return(false); } var engine = OcrEngine.TryCreateFromLanguage(langtag); if (engine == null) { return(false); } language = langtag; } catch { return(false); } return(true); }
public static async Task <string> GetText() { var language = new Windows.Globalization.Language("en-US"); using (var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer(language)) { await speechRecognizer.CompileConstraintsAsync(); speechRecognizer.StateChanged += SpeechRecognizerStateChangedHandler;; var result = await speechRecognizer.RecognizeAsync(); if (result.Status == SpeechRecognitionResultStatus.Success) { return(result.Text); } else { // we need to control confidence and other factors } } return(null); }
private async void buttonVoice_Click(object sender, RoutedEventArgs e) { // 音声認識をやるには。。。 // Windowsの設定で'オンライン音声認識'を検索しオンにする var language = new Windows.Globalization.Language("ja-JP"); var slangs = SpeechRecognizer.SupportedTopicLanguages; foreach (var slang in slangs) { var name = slang.DisplayName; } var langs = SpeechRecognizer.SupportedGrammarLanguages; foreach (var lang in langs) { var name = lang.DisplayName; } // Create an instance of SpeechRecognizer. var speechRecognizer = new SpeechRecognizer(language); // Listen for audio input issues. speechRecognizer.RecognitionQualityDegrading += SpeechRecognizer_RecognitionQualityDegrading; // Add a web search grammar to the recognizer. var webSearchGrammar = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, "webSearch"); speechRecognizer.UIOptions.AudiblePrompt = "Say magic word..."; speechRecognizer.UIOptions.ExampleText = voiceKeywords; await speechRecognizer.CompileConstraintsAsync(); // Start recognition. var speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync(); //await speechRecognizer.RecognizeWithUIAsync(); ShowLog($"Speech Recoginition Result - '{speechRecognitionResult.Text}'"); var resultWord = speechRecognitionResult.Text; var voiceKeys = voiceKeywords.Split(","); if (voiceKeys.Where(i => i.ToLower().Contains(resultWord.ToLower())).Count() > 0) { if (resultWord == "ジャパン") { resultWord = "japan"; } if (resultWord == "クリア") { resultWord = "clear"; } if (!string.IsNullOrEmpty(resultWord)) { var orderToTarget = new { word = resultWord, timestamp = DateTime.Now }; var content = Newtonsoft.Json.JsonConvert.SerializeObject(orderToTarget); var msg = new Message(System.Text.Encoding.UTF8.GetBytes(content)); msg.Properties.Add("app", "led"); await deviceClient.SendEventAsync(msg); ShowLog($"Send to IoT Hub - '{content}'"); } } }
static void scanFolder(Options _op) { op = _op; //OCRエンジン初期化 OcrEngine engine = null; try { var lang = new Windows.Globalization.Language(op.Lang); if (!OcrEngine.IsLanguageSupported(lang)) { Console.Write("-lang {0}はOCRに対応していない言語です。\n", op.Lang); foreach (var l in OcrEngine.AvailableRecognizerLanguages) { Console.Write("\t-l {0}\t{1}\n", l.LanguageTag, l.DisplayName); } Console.WriteLine("ms-settings:regionlanguage\n設定>時刻と言語>言語>+優先する言語を追加する>English(United States)\n設定からen-USを追加・ダウンロードしてください。"); Environment.Exit(1); } engine = OcrEngine.TryCreateFromLanguage(lang); if (engine == null) { Console.WriteLine("OCR初期化に失敗しました。"); Environment.Exit(1); } } catch (Exception e) { Console.Write("Error\n{0}\n", e); Environment.Exit(1); } var isbns = new List <ISBN>(); //指定フォルダ if (System.IO.Directory.Exists(op.Input)) { var filelist = System.IO.Directory.GetFiles(op.Input); var lastfile = ""; //先頭から指定ファイル数をOCR var count = op.Head; foreach (var file in filelist) { if (count <= 0) { break; } lastfile = file; Console.Write("Scan: {0}\n", file); try { var result = scanFromImage(file, engine); result.Wait(); var n = result.Result; if (n.Count > 0) { isbns.AddRange(n); if (op.Skip) { break; } } count--; } catch (Exception e) { if ((UInt32)e.InnerException.HResult == (UInt32)0x88982F50) { //画像出ない } else { Console.Write("error\n{0}\n", e); } } } //最後尾から指定ファイル数をOCR Array.Reverse(filelist); count = op.Tail; foreach (var file in filelist) { if (count <= 0) { break; } if (op.Skip && isbns.Count > 0) { break; } if (file == lastfile) { break; } Console.Write("Scan: {0}\n", file); try { var result = scanFromImage(file, engine); result.Wait(); var n = result.Result; if (n.Count > 0) { isbns.AddRange(n); } count--; } catch (Exception e) { if ((UInt32)e.InnerException.HResult == (UInt32)0x88982F50) { //画像ではない } else { Console.Write("error\n{0}\n", e); } } } } else if (System.IO.File.Exists(op.Input)) { Console.Write("Scan: {0}\n", op.Input); try { var result = scanFromImage(op.Input, engine); result.Wait(); var n = result.Result; if (n.Count > 0) { isbns.AddRange(n); } } catch (Exception e) { if ((UInt32)e.InnerException.HResult == (UInt32)0x88982F50) { //画像出ない } else { Console.Write("error\n{0}\n", e); } } } else { Console.WriteLine("対象を指定してください"); Environment.Exit(1); } if (isbns.Count > 0) { //HITしたISBNをまとめて var isbnMap = new Dictionary <string, int>(); foreach (var isbn in isbns) { if (isbnMap.ContainsKey(isbn.ISBN13)) { isbnMap[isbn.ISBN13] += isbn.Rank; } else { isbnMap[isbn.ISBN13] = isbn.Rank; } } //ランクが高いISBNを一つ選択する { string isbn = ""; int max = 0; foreach (var k in isbnMap) { if (k.Value > max) { isbn = k.Key; max = k.Value; } } if (max > 0) { Console.WriteLine("ISBN: " + isbn); if (op.Out != null && op.Out != "") { System.IO.File.WriteAllText(op.Out, isbn); Console.WriteLine("output: " + op.Out); } } } } }
private async Task Fileupdate() { var topUserLanguage = Windows.System.UserProfile.GlobalizationPreferences.Languages[0]; var language = new Windows.Globalization.Language(topUserLanguage); var displayName = language.Script; String currentLang = ""; if (localSettings.Values["language"] == null) { if (localSettings.Values["first"] == null) //第一次启动,语言值为空 { switch (displayName) //选择App语言 { case "Hans": currentLang = "Hans"; break; case "Hant": currentLang = "Hant"; break; case "Jpan": currentLang = "Jpan"; break; case "Kore": currentLang = "Kore"; break; default: currentLang = "EN"; break; } localSettings.Values["language"] = currentLang; //设置语言值为当前系统语言 StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///EMU" + currentLang + ".db")); //选择当前语言数据库 StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder; await file.CopyAsync(folder); StorageFile current = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("EMU" + currentLang + ".db"); //复制数据库到LocalState目录 await current.RenameAsync("EMU.db"); localSettings.Values["first"] = "2016-07-31"; //写入当前数据库版本值 } } else if (localSettings.Values["language"].ToString() != displayName) //用户切换系统语言 { switch (displayName) //选择App语言 { case "Hans": currentLang = "Hans"; break; case "Hant": currentLang = "Hant"; break; case "Jpan": currentLang = "Jpan"; break; case "Kore": currentLang = "Kore"; break; default: currentLang = "EN"; break; } StorageFile current = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("EMU.db"); await current.DeleteAsync(); //删除旧语言版本数据库 StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///EMU" + currentLang + ".db")); //选择当前语言数据库 StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder; await file.CopyAsync(folder); current = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("EMU" + currentLang + ".db"); //复制数据库到LocalState目录 await current.RenameAsync("EMU.db"); localSettings.Values["first"] = "2016-07-31"; //写入当前数据库版本值 localSettings.Values["language"] = currentLang; //设置语言值为当前系统语言 } }
private async void VoiceButton_Click(object sender, RoutedEventArgs e) { try { // Get the top user-preferred language and its display name. var topUserLanguage = Windows.System.UserProfile.GlobalizationPreferences.Languages[0]; var language = new Windows.Globalization.Language(topUserLanguage); firstStopAttemptDone = false; listening = true; using (speechRecognizer = new SpeechRecognizer(language)) { var dictationConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, WEB_SEARCH); speechRecognizer.Constraints.Add(dictationConstraint); SpeechRecognitionCompilationResult compilationResult = await speechRecognizer.CompileConstraintsAsync(); // setting timeouts speechRecognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(4.0); speechRecognizer.Timeouts.BabbleTimeout = TimeSpan.FromSeconds(4.0); speechRecognizer.Timeouts.EndSilenceTimeout = TimeSpan.FromSeconds(1.0); speechRecognizer.HypothesisGenerated += SpeechRecognizer_HypothesisGenerated; if (compilationResult.Status != SpeechRecognitionResultStatus.Success) return; VisualStateManager.GoToState(this, VISUAL_STATE_LISTENING, true); this.IsReadOnly = true; this.Text = LISTENING_TEXT; SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeAsync(); if (speechRecognitionResult.Status == SpeechRecognitionResultStatus.Success) Text = speechRecognitionResult.Text; else Text = SPEECH_RECOGNITION_FAILED; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); Text = string.Empty; } finally { timer.Stop(); hypotesis = string.Empty; VisualStateManager.GoToState(this, VISUAL_STATE_NOT_LISTENING, true); this.IsReadOnly = false; listening = false; } }
private async void btnSearch_Click(object sender, RoutedEventArgs e) { this.txtCortanaMessages.Text = "Je vous écoute..."; Windows.Globalization.Language langFR = new Windows.Globalization.Language("fr-FR"); SpeechRecognizer recognizer = new SpeechRecognizer(langFR); SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development"); recognizer.Constraints.Add(topicConstraint); await recognizer.CompileConstraintsAsync(); // Required var recognition = recognizer.RecognizeAsync(); recognition.Completed += this.Recognition_Completed; }
private void OnLanguageChanged(object sender, Windows.Globalization.Language e) { SetSelectedItemBySelectedLanguage(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { LanguageValues = new List <LanguageValue>(); // First show the default setting // LanguageValues.Add(new LanguageValue() { DisplayName = "Use language preferences (recommended)", LanguageTag = "" }); // If there are app languages that the user speaks, show them next // Note: the first (non-override) language, if set as the primary language override // would give the same result as not having any primary language override. There's // still a difference, though: If the user changes their language preferences, the // default setting (no override) would mean that the actual primary app language // could change. But if it's set as an override, then it will remain the primary // app language after the user changes their language preferences. // Add machine preferred languages /* * for (var i = 0; i < Windows.Globalization.ApplicationLanguages.Languages.Count; i++) * { * var lang = new Windows.Globalization.Language(Windows.Globalization.ApplicationLanguages.Languages[i]); * LanguageValues.Add(new LanguageValue() { DisplayName = lang.NativeName, LanguageTag = lang.LanguageTag }); * }*/ // Add application manifest languages for (var i = 0; i < Windows.Globalization.ApplicationLanguages.ManifestLanguages.Count; i++) { var lang = new Windows.Globalization.Language(Windows.Globalization.ApplicationLanguages.ManifestLanguages[i]); LanguageValues.Add(new LanguageValue() { DisplayName = lang.NativeName, LanguageTag = lang.LanguageTag }); } MachineLanguages.Text = GetAppLanguagesAsFormattedString(Windows.Globalization.ApplicationLanguages.Languages); ManifestLanguages.Text = GetAppLanguagesAsFormattedString(Windows.Globalization.ApplicationLanguages.ManifestLanguages); int selectIndex = -1; int index = 0; foreach (var l in LanguageValues) { LanguageCombo.Items.Add(l); if (FindCurrent(l) == true) { selectIndex = index; } index++; } if (LanguageCombo.Items.Count > 0) { if (selectIndex != -1) { LanguageCombo.SelectedIndex = selectIndex; } else { // if PrimaryLanguageOverride not set, select first language in the list LanguageCombo.SelectedIndex = 0; } } lastSelectionIndex = LanguageCombo.SelectedIndex; LanguageCombo.SelectionChanged += LanguageCombo_SelectionChanged; var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); this.AppDescription.Text = resourceLoader.GetString("appDescription"); }