Exemplo n.º 1
0
        private void stopRecording()
        {
            btnRecord.Image = Properties.Resources.Speak_On;
            stopTimerRecordingDuration();

            soundRecorder?.Stop(); // data are in callback method ....
        }
Exemplo n.º 2
0
        public static void RecordMode(string libraryName, string text, string outputFilename)
        {
            SoundRecorder recorder = new SoundRecorder(outputFilename);

            recorder.PostWait = 300;

            var engines = SpeechController.GetVoiceroid2SpeechEngine();
            var engine  = SpeechController.GetVoiceroid2Instance(libraryName);

            if (engine == null)
            {
                Console.WriteLine($"{libraryName} を起動できませんでした。");
                return;
            }

            engine.Activate();
            engine.Finished += (s, a) =>
            {
                Task t = recorder.Stop();
                t.Wait();
                finished = true;
                engine.Dispose();
            };
            recorder.Start();
            engine.Play(text);
        }
Exemplo n.º 3
0
        private static void WhisperMode(string libraryName, string text)
        {
            string tempFile    = "normal.wav";
            string whisperFile = "whisper.wav";

            var engines = SpeechController.GetVoiceroid2SpeechEngine();
            var engine  = SpeechController.GetVoiceroid2Instance(libraryName);

            if (engine == null)
            {
                Console.WriteLine($"{libraryName} を起動できませんでした。");
                return;
            }
            engine.Activate();

            SoundRecorder recorder = new SoundRecorder(tempFile);

            {
                recorder.PostWait = 300;

                engine.Finished += (s, a) =>
                {
                    finished = true;
                };

                recorder.Start();
                engine.Play(text);
            }

            while (!finished)
            {
                Thread.Sleep(100);
            }
            engine.Dispose();
            Task t = recorder.Stop();

            t.Wait();
            // ささやき声に変換
            Whisper whisper = new Whisper();
            Wave    wave    = new Wave();

            wave.Read(tempFile);
            whisper.Convert(wave);
            wave.Write(whisperFile, wave.Data);

            //// 変換した音声を再生
            SoundPlayer sp = new SoundPlayer();

            sp.Play(whisperFile);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            bool showUsage = true;

            if (args.Length >= 1) // requires port at least
            {
                try
                {
                    // todo: validate with a regex (ip or name)

                    int port = int.Parse(args[0]);
                    if (port > 0 && port < 65536)
                    {
                        showUsage = false;

                        String adrs = "127.0.0.1";
                        if (args.Length >= 2) adrs = args[1];

                        // todo: retreive list of devices and select from/display it in Show Usage

                        // todo: parse and set these parameters
                        SampleRate rate = SampleRate.Rate11KHz;
                        SampleSize size = SampleSize.Bits8;
                        short channels = 1;

                        SoundRecorder recorder = new SoundRecorder(SoundDeviceType.Default, rate, size, channels);
                        UdpClient udpClient = new UdpClient(adrs, port);
                        Console.WriteLine("Sending sound packets on UDP port " + port);
                        try
                        {
                            recorder.Start("");
                            while (recorder.Capturing())
                            {
                                //Sit here and wait for a message to arrive
                                recorder.NotificationEvent.WaitOne(System.Threading.Timeout.Infinite, true);

                                recorder.SendCapturedData(udpClient);
                            }

                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                            Console.WriteLine("Hit any key to continue");
                            Console.ReadKey();
                        }
                        finally
                        {
                            recorder.Stop();
                            udpClient.Close();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            if (showUsage)
            {
                Console.WriteLine("Send direct sound data as UDP packets.");
                Console.WriteLine("USAGE: UDPSoundSender targetIP port [8000 8 1]");
                Console.WriteLine("where:");
                Console.WriteLine("  targetIP is address where to send the packets (yes, multicast addresses should works!)");
                Console.WriteLine("  port is the one of the target ip listening");
                Console.WriteLine("  [optional parameters]");
                Console.WriteLine("  8000 is the default sample rate (choose 8000, 11025, 22050, 44100 or 48000 sample/sec)");
                Console.WriteLine("  8 is the default bit depth (choose 8 or 16 bits)");
                Console.WriteLine("  1 is the channels selected (choose 1 or 2 channels)");

                Console.WriteLine("Hit any key to exit");
                Console.Read();
            }
        }