// Use this for initialization void Start() { // テキストを渡すスクリプトの参照 textMesh = GameObject.Find("Word"); controller = textMesh.GetComponent <TextController>(); // 音声認識セッションの初期化 session = PXCMSession.CreateInstance(); source = session.CreateAudioSource(); PXCMAudioSource.DeviceInfo dinfo = null; source.QueryDeviceInfo(1, out dinfo); source.SetDevice(dinfo); Debug.Log(dinfo.name); session.CreateImpl <PXCMSpeechRecognition>(out sr); PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(out pinfo); pinfo.language = PXCMSpeechRecognition.LanguageType.LANGUAGE_JP_JAPANESE; sr.SetProfile(pinfo); handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = (x) => controller.SetText(x.scores[0].sentence); sr.SetDictation(); sr.StartRec(source, handler); }
public void EnableRecognition(SupportedLanguage language) { _session = PXCMSession.CreateInstance(); var audioSource = FindAudioSource(); _session.CreateImpl(out _speechRecognition); for (int i = 0; ; i++) { PXCMSpeechRecognition.ProfileInfo profile; if (_speechRecognition.QueryProfile(i, out profile) != Errors.NoError) { break; } var languageLabel = profile.language.ToString(); SupportedLanguage sdkLanguage = SupportedLanguageMapper.FromString(languageLabel); if (sdkLanguage != SupportedLanguage.NotSpecified) { _recognitionProfiles.Add(sdkLanguage, profile); } } if (language == SupportedLanguage.NotSpecified) { language = _recognitionProfiles.Keys.First(); } if (!_recognitionProfiles.ContainsKey(language)) { throw new LanguageNotSupportedException(language); } _speechRecognition.SetProfile(_recognitionProfiles[language]); _speechRecognition.SetDictation(); _speechRecognition.StartRec(audioSource, _speechRecognitionHandler); }
public void Start() { filePath = Application.dataPath + @"\LogData.txt"; File.CreateText(filePath); //インスタンスの生成 session = PXCMSession.CreateInstance(); //音声データの入力 source = session.CreateAudioSource(); PXCMAudioSource.DeviceInfo dinfo = null; //デバイスを検出して出力 source.QueryDeviceInfo(0, out dinfo); source.SetDevice(dinfo); Debug.Log(dinfo.name); //音声認識 session.CreateImpl <PXCMSpeechRecognition>(out sr); //音声認識の初期設定 PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(out pinfo); pinfo.language = PXCMSpeechRecognition.LanguageType.LANGUAGE_JP_JAPANESE; sr.SetProfile(pinfo); //handlerにメソッドを渡す工程 handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = (x) => Dataoutput(x.scores[0].sentence, x.duration); sr.SetDictation(); }
/// <summary> /// Configures the speech recognition. /// </summary> private bool ConfigureSpeechRecognition() { /* Create the AudioSource instance */ source = session.CreateAudioSource(); /* Set audio volume to 0.2 */ source.SetVolume(0.2f); /* Set Audio Source */ source.SetDevice(sourceDeviceInfo[_activeSource]); /* Set Module */ PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid = modulesIuID[_activeModule]; pxcmStatus sts = session.CreateImpl <PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { /* Configure */ PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(_activeLanguage, out pinfo); sr.SetProfile(pinfo); /* Set Command/Control or Dictation */ if (SpeechModuleMode == SpeechModuleModeType.CommandControl) { string[] cmds = Commands; if (cmds != null && cmds.GetLength(0) != 0) { // voice commands available, use them sr.BuildGrammarFromStringList(1, cmds, null); sr.SetGrammar(1); } else { Debug.Log("Speech Command List Empty!"); SetError(SpeechManagerErrorType.VoiceThreadError_CommandsListEmpty); //Switch to dictaction mode //SpeechModuleMode = SpeechModuleModeType.Dictation; //sr.SetDictation(); } } else { sr.SetDictation(); } } else { Debug.Log("VoiceThreadError - InitFailed - CreateImpl!"); SetError(SpeechManagerErrorType.VoiceThreadError_InitFailed_CreateImpl); return(false); } return(true); }
void SetDictationMode() { // ディクテーションモードを設定する var sts = recognition.SetDictation(); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new Exception("ディクテーションモードの設定に失敗しました"); } }
void initSession(PXCMSession session) { if (source == null) { Debug.Log("Source was null! No audio device?"); return; } // Set audio volume to 0.2 source.SetVolume(setVolume); // Set Audio Source Debug.Log("Using device: " + device.name); source.SetDevice(device); // Set Module PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid = 0; pxcmStatus sts = session.CreateImpl <PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { // Configure PXCMSpeechRecognition.ProfileInfo pinfo; // Language sr.QueryProfile(0, out pinfo); Debug.Log(pinfo.language); sr.SetProfile(pinfo); // Set Command/Control or Dictation sr.SetDictation(); // Initialization Debug.Log("Init Started"); PXCMSpeechRecognition.Handler handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = OnRecognition; handler.onAlert = OnAlert; sts = sr.StartRec(source, handler); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.Log("Voice Rec Started"); } else { Debug.Log("Voice Rec Start Failed"); } } else { Debug.Log("Voice Rec Session Failed"); } }
public void Start() { session = PXCMSession.CreateInstance(); source = session.CreateAudioSource(); PXCMAudioSource.DeviceInfo dinfo = null; source.QueryDeviceInfo(1, out dinfo); source.SetDevice(dinfo); session.CreateImpl <PXCMSpeechRecognition>(out sr); PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(out pinfo); pinfo.language = PXCMSpeechRecognition.LanguageType.LANGUAGE_JP_JAPANESE; sr.SetProfile(pinfo); handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = (x) => Debug.Log(x.scores[0].sentence); sr.SetDictation(); sr.StartRec(source, handler); }
public void DoIt(MainForm form1, PXCMSession session) { form = form1; /* Create the AudioSource instance */ source = session.CreateAudioSource(); if (source == null) { CleanUp(); form.PrintStatus("Stopped"); return; } /* Set audio volume to 0.2 */ source.SetVolume(0.2f); /* Set Audio Source */ source.SetDevice(form.GetCheckedSource()); /* Set Module */ PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid = form.GetCheckedModule(); pxcmStatus sts = session.CreateImpl <PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { /* Configure */ PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(form.GetCheckedLanguage(), out pinfo); sr.SetProfile(pinfo); ///////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// /* Set Command/Control or Dictation */ if (form.IsCommandControl()) { string[] cmds = form.GetCommands(); if (form.g_file != null && form.g_file.Length != 0) { if (form.g_file.EndsWith(".list")) { form.FillCommandListConsole(form.g_file); cmds = form.GetCommands(); if (cmds.GetLength(0) == 0) { form.PrintStatus("Command List Load Errors"); } } // input Command/Control grammar file available, use it if (!SetGrammarFromFile(form.g_file)) { form.PrintStatus("Can not set Grammar From File."); CleanUp(); return; } ; } else if (cmds != null && cmds.GetLength(0) != 0) { // voice commands available, use them sts = sr.BuildGrammarFromStringList(1, cmds, null); sts = sr.SetGrammar(1); } else { form.PrintStatus("No Command List. Dictation instead."); if (form.v_file != null && form.v_file.Length != 0) { SetVocabularyFromFile(form.v_file); } sts = sr.SetDictation(); } } else { if (form.v_file != null && form.v_file.Length != 0) { SetVocabularyFromFile(form.v_file); } sts = sr.SetDictation(); } if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { form.PrintStatus("Can't start recognition."); CleanUp(); return; } /* Initialization */ form.PrintStatus("Init Started"); form.PutLabel1Text("初期化中..."); PXCMSpeechRecognition.Handler handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = OnRecognition; handler.onAlert = OnAlert; sts = sr.StartRec(source, handler); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { form.PrintStatus("Init OK"); // form.PutLabel1Text("認識中..."); form.PutLabel1Text("マイクに向かって話してください"); /* Wait until the stop button is clicked */ while (!form.IsStop()) { System.Threading.Thread.Sleep(5); } sr.StopRec(); } else { form.PrintStatus("Failed to initialize"); } } else { form.PrintStatus("Init Failed"); } CleanUp(); form.PrintStatus("Stopped"); }