public void StartVoice(RecordMode mode, string lang)
        {
            Speech             = new SpeechTask();
            Speech.Language    = lang;
            Speech.KeepWavFile = $@"R:\Voice{DateTime.Now.ToString("mmss")}.wav";

            var setting = Control.Share.Setting;
            var min     = setting.MinLength;
            var max     = setting.MaxLength;

            if (mode == RecordMode.File)
            {
                Task = Speech.StartRecord(min, max);
            }
            else if (mode == RecordMode.Stream)
            {
                Task = Speech.StartStream();
            }
        }
        static void Main()
        {
            const int        testVoice = 5;
            OptionalDebugger debugger  = new OptionalDebugger();

            debugger.entryPoint.Initialise();

            byte[] testPacket = debugger.GetTestPacket(debugger.allTestWords);
            debugger.entryPoint.OnReceivedPacket(testPacket);

            while (debugger.entryPoint.OutputManager.IsProcessingOutputs)
            {
                debugger.entryPoint.UpdateBeforeSimulation();
            }
            SpeechTask currentTask = debugger.entryPoint.OutputManager.Speeches[testVoice];

            debugger.StoreDictionaryWords(currentTask.Worker.PossibleDebugOutput.DictionaryWords);
            debugger.StoreRuleBasedWords(currentTask.Worker.PossibleDebugOutput.RuleBasedWords);
            debugger.PrintResults(currentTask.Worker.Pronunciation.WrongFormatMatches,
                                  currentTask.Worker.Pronunciation.WrongFormatNonMatches);
            debugger.entryPoint.Dispose();
        }
Example #3
0
        /// <summary>
        /// 語音傳文字
        /// </summary>
        public Task VoiceToText(string path)
        {
            return(Task.Run(async() =>
            {
                try
                {
                    // 傳送音頻檔至Google
                    WriteLog($"VoiceToText:{path}");
                    var speech = await SpeechTask.FromFile(path, Language);
                    var text = string.Empty;
                    if (!string.IsNullOrEmpty(speech.Text))
                    {
                        text = speech.Text;
                        text += Environment.NewLine;

                        // 模擬打字
                        InputText(text);
                    }
                    Response[path] = speech.Text;

                    if (!Setting.KeepWavFile)
                    {
                        try
                        {
                            File.Delete(path);
                        }
                        catch { }
                    }

                    MainWindow.Balloon($"Google say: {speech.Text}");
                }
                catch (Exception ex)
                {
                    Control.WriteLog(ex.Message);
                    Control.WriteLog(ex.StackTrace);
                    //throw ex;
                }
            }));
        }