Ejemplo n.º 1
0
        static void StartRecognition()
        {
            var audioDirectory  = Path.Combine(Directory.GetCurrentDirectory(), "Audio");
            var audioCollection = new Dictionary <string, FileInfo>();

            foreach (var item in Directory.GetFiles(audioDirectory))
            {
                var audioFile = new FileInfo(item);
                audioCollection.Add(audioFile.Name, audioFile);
            }

            var audioListString = string.Join(" \n", audioCollection.Keys);

            Console.WriteLine(@"Which file to use -> {0}", audioListString);
            var response = Console.ReadLine();

            if (string.IsNullOrEmpty(response))
            {
                response = "robot.wav";
            }

            _recognizer.StartRecognition(new FileStream(Path.Combine(audioDirectory, response), FileMode.Open));

            Console.WriteLine(@"Press any key to start Speech Recognition...");
            Console.ReadLine();

            var result = _recognizer.GetResult();

            _recognizer.StopRecognition();
            if (result != null)
            {
                Console.WriteLine(result.GetHypothesis());
            }
        }
        public void Transcribe_UsingGrammar_Continuous()
        {
            _configuration = new Configuration
            {
                AcousticModelPath = ModelsDirectory,
                DictionaryPath    = _dictionaryPath,
                LanguageModelPath = _languageModelPath,
                UseGrammar        = true,
                GrammarName       = "hello",
                GrammarPath       = ModelsDirectory
            };

            _speechRecognizer = new StreamSpeechRecognizer(_configuration);

            for (int i = 1; i <= 3; i++)//TODO: Reading 3 or more files in a row causes test fail (The same happens in CMU Sphinx4)
            {
                var audioFile = Path.Combine(Directory.GetCurrentDirectory(), "Audio", string.Format("Long Audio {0}.wav", i));
                var stream    = new FileStream(audioFile, FileMode.Open);
                _speechRecognizer.StartRecognition(stream);
                var result = _speechRecognizer.GetResult();
                _speechRecognizer.StopRecognition();
                Assert.IsNotNull(result);
                var hypothesis = result.GetHypothesis();
                Assert.IsTrue(hypothesis.Contains("the time is now exactly twenty five to one") || hypothesis.Contains("there's three left on the left side the one closest to us"));
            }
        }
Ejemplo n.º 3
0
        public async Task <string> ProcessVoiceToText(Stream stream, int bitRate)
        {
            var fn = $"a-{Guid.NewGuid()}-{bitRate}.wav";

            stream.Seek(0, SeekOrigin.Begin);
            var wavStream = new RawSourceWaveStream(stream, new WaveFormat(bitRate, 2));

            // Debugging only
            // WaveFileWriter.CreateWaveFile($"{fn}-source.wav", wavStream);

            stream.Seek(0, SeekOrigin.Begin);
            var newFormat = new WaveFormat(InputRate, 1);
            WaveFormatConversionStream cs = new WaveFormatConversionStream(newFormat, wavStream);

            // Debugging only
            // WaveFileWriter.CreateWaveFile(fn, cs);
            cs.Seek(0, SeekOrigin.Begin);
            speechRecognizer.StartRecognition(cs);
            var result = speechRecognizer.GetResult();

            speechRecognizer.StopRecognition();

            cs.Close();
            return(result?.GetHypothesis());
        }
Ejemplo n.º 4
0
        private static string GetTranscription(string audioDirectory, string audioFile, string modelsDirectory)
        {
            try
            {
                if (!Directory.Exists(modelsDirectory) || !Directory.Exists(audioDirectory))
                {
                    return("No Models or Audio directory found!! Aborting...");
                }

                var speechConfiguration = new Configuration
                {
                    AcousticModelPath = modelsDirectory,
                    DictionaryPath    = Path.Combine(modelsDirectory, "cmudict-en-us.dict"),
                    LanguageModelPath = Path.Combine(modelsDirectory, "en-us.lm.dmp"),
                    UseGrammar        = true,
                    GrammarPath       = modelsDirectory,
                    GrammarName       = "hello"
                };
                var speechRecognizer = new StreamSpeechRecognizer(speechConfiguration);
                var stream           = new FileStream(audioFile, FileMode.Open);
                speechRecognizer.StartRecognition(stream);

                Console.WriteLine("Transcribing...");
                var result = speechRecognizer.GetResult();

                return(result != null?result.GetHypothesis() : "Sorry! Coudn't Transcribe");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
 public void StartRecognition(Stream stream)
 {
     try
     {
         CanTranscribe = false;
         _recognizer.StartRecognition(stream);
         var result = _recognizer.GetResult();
         _recognizer.StopRecognition();
         if (result != null)
         {
             MessageBox.Show(result.GetHypothesis());
         }
         stream.Close();
         CanTranscribe = true;
     }
     catch (Exception exception)
     {
         this.LogError(exception);
     }
 }
Ejemplo n.º 6
0
        private void recognize()
        {
            waveInStream.StopRecording();
            mem.Position = 0;
            _recognizer.StartRecognition(mem, new TimeFrame(mem.Length));
            SpeechResult result = _recognizer.GetResult();

            _recognizer.StopRecognition();
            Console.WriteLine("result: " + result.GetHypothesis());
            Console.ReadKey();
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        private static void Main()
        {
            Logger.LogReceived += LogReceived;
            var modelsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Models");
            var audioDirectory  = Path.Combine(Directory.GetCurrentDirectory(), "Audio");

            if (!Directory.Exists(modelsDirectory) || !Directory.Exists(audioDirectory))
            {
                Console.WriteLine("No Models or Audio directory found!! Aborting...");
                Console.ReadLine();
                return;
            }

            _speechConfiguration = new Configuration
            {
                AcousticModelPath = modelsDirectory,
                DictionaryPath    = Path.Combine(modelsDirectory, "cmudict-en-us.dict"),
                LanguageModelPath = Path.Combine(modelsDirectory, "en-us.lm.dmp"),
                UseGrammar        = true,
                GrammarPath       = modelsDirectory,
                GrammarName       = "hello"
            };

            _speechRecognizer = new StreamSpeechRecognizer(_speechConfiguration);
            for (int i = 1; i <= 3; i++)
            {
                var audioFile = Path.Combine(audioDirectory, String.Format("Long Audio {0}.wav", i));
                var stream    = new FileStream(audioFile, FileMode.Open);
                if (i == 3)
                {
                    System.Diagnostics.Trace.WriteLine("checking");
                }
                _speechRecognizer.StartRecognition(stream);
                var result = _speechRecognizer.GetResult();
                _speechRecognizer.StopRecognition();
                if (result != null)
                {
                    Console.WriteLine(string.Format("Result: {0}", i) + result.GetHypothesis());
                }
                else
                {
                    Console.WriteLine("Result: {0}", "Sorry! Coudn't Transcribe");
                }
                var instance = ConfigurationManager.GetInstance <SpeechMarker>();
                Console.WriteLine(instance.ToString());
                stream.Close();
            }
            Console.WriteLine("DONE!");
            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            Logger.LogReceived += LogReceived;

            var modelsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Models");
            var audioDirectory  = Path.Combine(Directory.GetCurrentDirectory(), "Audio");
            var audioFile       = Path.Combine(audioDirectory, "Long Audio 2.wav");

            if (!Directory.Exists(modelsDirectory) || !Directory.Exists(audioDirectory))
            {
                Console.WriteLine("No Models or Audio directory found!! Aborting...");
                Console.ReadLine();
                return;
            }

            speechConfiguration = new Configuration();
            speechConfiguration.AcousticModelPath = modelsDirectory;
            speechConfiguration.DictionaryPath    = Path.Combine(modelsDirectory, "cmudict-en-us.dict");
            speechConfiguration.LanguageModelPath = Path.Combine(modelsDirectory, "en-us.lm.dmp");

            speechConfiguration.UseGrammar  = true;
            speechConfiguration.GrammarPath = modelsDirectory;
            speechConfiguration.GrammarName = "hello";


            speechRecognizer = new StreamSpeechRecognizer(speechConfiguration);
            var stream = new FileStream(audioFile, FileMode.Open);

            speechRecognizer.StartRecognition(stream);

            Console.WriteLine("Transcribing...");
            var result = speechRecognizer.GetResult();

            if (result != null)
            {
                Console.WriteLine("Result: " + result.GetHypothesis());
            }
            else
            {
                Console.WriteLine("Sorry! Coudn't Transcribe");
            }

            Console.ReadLine();
        }
        public void Transcribe_UsingGrammar()
        {
            _configuration = new Configuration
            {
                AcousticModelPath = ModelsDirectory,
                DictionaryPath    = _dictionaryPath,
                LanguageModelPath = _languageModelPath,
                UseGrammar        = true,
                GrammarName       = "hello",
                GrammarPath       = ModelsDirectory
            };

            var audioFile = Path.Combine(Directory.GetCurrentDirectory(), "Audio", "robot.wav");

            _speechRecognizer = new StreamSpeechRecognizer(_configuration);
            _speechRecognizer.StartRecognition(new FileStream(audioFile, FileMode.Open));

            var result = _speechRecognizer.GetResult();

            Assert.IsNotNull(result);
            Assert.AreEqual("the time is now exactly twenty five to one", result.GetHypothesis());
        }
		public static void Main (string[] args)
		{
			Logger.LogReceived += LogReceived;

			var modelsDirectory = Path.Combine (Directory.GetCurrentDirectory (), "Models");
			var audioDirectory = Path.Combine (Directory.GetCurrentDirectory (), "Audio");
			var audioFile = Path.Combine (audioDirectory, "Long Audio 2.wav");

			if (!Directory.Exists (modelsDirectory)||!Directory.Exists(audioDirectory)) {
				Console.WriteLine ("No Models or Audio directory found!! Aborting...");
				Console.ReadLine ();
				return;
			}

			speechConfiguration = new Configuration ();
			speechConfiguration.AcousticModelPath=modelsDirectory;
			speechConfiguration.DictionaryPath = Path.Combine (modelsDirectory, "cmudict-en-us.dict");
			speechConfiguration.LanguageModelPath = Path.Combine (modelsDirectory, "en-us.lm.dmp");

			speechConfiguration.UseGrammar = true;
			speechConfiguration.GrammarPath = modelsDirectory;
			speechConfiguration.GrammarName = "hello";


			speechRecognizer = new StreamSpeechRecognizer (speechConfiguration);
			var stream = new FileStream (audioFile, FileMode.Open);
			speechRecognizer.StartRecognition (stream);

			Console.WriteLine ("Transcribing...");
			var result = speechRecognizer.GetResult ();

			if (result != null) {
				Console.WriteLine ("Result: " + result.GetHypothesis ());
			} else {
				Console.WriteLine ("Sorry! Coudn't Transcribe");
			}

			Console.ReadLine ();
		}