Esempio n. 1
0
        public static void RecordMode(string libraryName, string text, string outputFilename)
        {
            SoundRecorder recorder = new SoundRecorder(outputFilename);

            recorder.PostWait = 300;

            var engines = SpeechController.GetAllSpeechEngine();
            var engine  = SpeechController.GetInstance(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);
        }
Esempio n. 2
0
        private static void OneShotPlayMode(string libraryName, string text, EngineParameters ep)
        {
            var engines = SpeechController.GetAllSpeechEngine();
            var engine  = SpeechController.GetInstance(libraryName);

            if (engine == null)
            {
                Console.WriteLine($"{libraryName} を起動できませんでした。");
                return;
            }
            engine.Activate();
            engine.Finished += (s, a) =>
            {
                engine.Dispose();
            };
            if (ep.Volume > 0)
            {
                engine.SetVolume(ep.Volume);
            }
            if (ep.Speed > 0)
            {
                engine.SetSpeed(ep.Speed);
            }
            if (ep.Pitch > 0)
            {
                engine.SetPitch(ep.Pitch);
            }
            if (ep.PitchRange > 0)
            {
                engine.SetPitchRange(ep.PitchRange);
            }
            engine.Play(text);
        }
Esempio n. 3
0
        private static string[] GetLibraryName()
        {
            var engines = SpeechController.GetAllSpeechEngine();
            var names   = from c in engines
                          select c.LibraryName;

            return(names.ToArray());
        }
Esempio n. 4
0
        private static string[] GetLibraryName()
        {
            var engines = SpeechController.GetAllSpeechEngine();
            var names   = from c in engines
                          where Environment.Is64BitProcess == c.Is64BitProcess
                          select $"{c.LibraryName} [{c.EngineName}]";

            return(names.ToArray());
        }
Esempio n. 5
0
        private static void InteractiveMode()
        {
            // 利用可能な音声合成エンジンを列挙
            // Windows 10 (x64) 上での VOICEROID+, VOICEROID2, SAPI5 に対応
            // CeVIO(SAPI5) は Windows 10 (x64) では動作しないため表示されません
            Console.WriteLine("* 利用可能な音声合成エンジン *\r\n");
            Console.WriteLine("LibraryName,EngineName,EnginePath");
            var engines = SpeechController.GetAllSpeechEngine();

            foreach (var c in engines)
            {
                Console.WriteLine($"{c.LibraryName},{c.EngineName},{c.EnginePath}");
            }

            // ライブラリ名を入力(c.LibraryName列)
            Console.Write("\r\nLibraryName> ");
            name = Console.ReadLine().Trim();

            // 対象となるライブラリを実行
            var engine = SpeechController.GetInstance(name);

            if (engine == null)
            {
                Console.WriteLine($"{name} を起動できませんでした。");
                Console.ReadKey();
                return;
            }
            // 設定した音声の再生が終了したときに呼び出される処理を設定
            engine.Finished += Engine_Finished;

            // 音声合成エンジンを起動
            engine.Activate();
            string message = $"音声合成エンジン {engine.Info.EngineName}、{engine.Info.LibraryName}を起動しました。";

            engine.Play(message); // 音声再生は非同期実行される
            Console.WriteLine(message);
            engine.SetVolume(1.0f);

            string line = "";

            while (true)
            {
                line = Console.ReadLine();
                if (line.Trim() == "")
                {
                    engine.Dispose();
                    return;
                }
                engine.Stop();     // 喋っている途中に文字が入力されたら再生をストップ
                engine.Play(line); // 音声再生は非同期実行される
                Console.WriteLine($"Volume: {engine.GetVolume()}, Speed: {engine.GetSpeed()}, Pitch: {engine.GetPitch()}, PitchRange: {engine.GetPitchRange()}");
            }
        }
Esempio n. 6
0
        private void SetTTSEnginesToComboBox()
        {
            var engines = SpeechController.GetAllSpeechEngine().Select(x => $"{ x.LibraryName}").ToList();

            if (engines.Count() == 0)
            {
                MessageBox.Show("使用可能な音声合成ソフトウェアがインストールされていません");
                Environment.Exit(1);
                return;
            }
            comboBoxSelectTTS.ItemsSource = engines;
            comboBoxSelectTTS.Text        = engines[0];
            LibraryName = engines[0];
        }
Esempio n. 7
0
        private static void WhisperMode(string libraryName, string text)
        {
            string tempFile    = "normal.wav";
            string whisperFile = "whisper.wav";

            var engines = SpeechController.GetAllSpeechEngine();
            var engine  = SpeechController.GetInstance(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);
        }
Esempio n. 8
0
        private static void OneShotPlayMode(string libraryName, string text)
        {
            var engines = SpeechController.GetAllSpeechEngine();
            var engine  = SpeechController.GetInstance(libraryName);

            if (engine == null)
            {
                Console.WriteLine($"{libraryName} を起動できませんでした。");
                return;
            }
            engine.Activate();
            engine.Finished += (s, a) =>
            {
                finished = true;
                engine.Dispose();
            };
            engine.Play(text);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            // インストール済み音声合成ライブラリの列挙
            var names = GetLibraryName();

            Console.WriteLine("インストール済み音声合成ライブラリ");
            string bit = Environment.Is64BitProcess ? "64 bit" : "32 bit";

            Console.WriteLine($"※ このアプリケーションは {bit}プロセスのため、{bit}のライブラリのみが列挙されます。");
            Console.WriteLine("-----");
            if (names.Length == 0)
            {
                Console.WriteLine("利用可能な音声合成ライブラリが見つかりませんでした。");
                Console.WriteLine("何かキーを押してください。");
                Console.ReadKey();
                return;
            }
            foreach (var s in names)
            {
                Console.WriteLine(s);
            }
            Console.WriteLine("-----");

            // 接続先スピーカーの列挙
            Console.WriteLine("接続先スピーカー");
            Console.WriteLine("-----");
            devices = new CoreAudioController().GetPlaybackDevices();
            string speaker = (devices.ToArray())[0].FullName;

            foreach (var d in devices)
            {
                Console.WriteLine($"{d.FullName}");
            }
            Console.WriteLine("-----");

            // 待ち受けIPアドレス
            Console.WriteLine("接続先");
            Console.WriteLine("-----");
            string hostname = Dns.GetHostName();

            IPAddress[] adrList = Dns.GetHostAddresses(hostname);
            foreach (IPAddress address in adrList)
            {
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    // IPv4
                    Console.WriteLine($"http://{address.ToString()}:{port}");
                }
            }
            Console.WriteLine($"待機中...");

            var          defaultName = (SpeechController.GetAllSpeechEngine()).First().LibraryName;
            HttpListener listener    = new HttpListener();

            listener.Prefixes.Add($"http://*:{port}/");
            listener.Start();
            while (true)
            {
                HttpListenerResponse response = null;
                try
                {
                    HttpListenerContext context = listener.GetContext();
                    HttpListenerRequest request = context.Request;
                    response = context.Response;

                    if (context.Request.Url.AbsoluteUri.EndsWith("favicon.ico"))
                    {
                        // favicon は無視
                        response.StatusCode = 404;
                        continue;
                    }
                    else if (context.Request.Url.AbsoluteUri.IndexOf("?") < 0 && context.Request.Url.LocalPath != "/")
                    {
                        string path = "html" + context.Request.Url.LocalPath;
                        // ? が含まれない場合は /html 以下をレスポンスとして返す
                        byte[] body = File.ReadAllBytes(path);
                        response.StatusCode = 200;
                        if (path.EndsWith(".html"))
                        {
                            response.ContentType = "text/html; charset=utf-8";
                        }
                        response.OutputStream.Write(body, 0, body.Length);
                        continue;
                    }
                    var queryString     = HttpUtility.ParseQueryString(context.Request.Url.Query);
                    EngineParameters ep = new EngineParameters();

                    string voiceText  = DateTime.Now.ToString("HH時 mm分 ss秒です");
                    string voiceName  = defaultName;
                    string engineName = "";
                    if (queryString["text"] != null)
                    {
                        voiceText = queryString["text"];
                        voiceText = voiceText.Replace("{time}", DateTime.Now.ToString("HH時 mm分 ss秒"));
                    }
                    if (queryString["name"] != null)
                    {
                        voiceName = queryString["name"];
                    }
                    string location = "";
                    if (queryString["speaker"] != null)
                    {
                        speaker = queryString["speaker"];
                        ChangeSpeaker(speaker);
                        location = $"@{speaker}";
                    }
                    if (queryString["pitch"] != null)
                    {
                        ep.Pitch = Convert.ToSingle(queryString["pitch"]);
                    }
                    if (queryString["range"] != null)
                    {
                        ep.PitchRange = Convert.ToSingle(queryString["range"]);
                    }
                    if (queryString["volume"] != null)
                    {
                        ep.Volume = Convert.ToSingle(queryString["volume"]);
                    }
                    if (queryString["speed"] != null)
                    {
                        ep.Speed = Convert.ToSingle(queryString["speed"]);
                    }
                    if (queryString["engine"] != null)
                    {
                        engineName = queryString["engine"];
                    }


                    Console.WriteLine("=> " + context.Request.RemoteEndPoint.Address);

                    response.StatusCode  = 200;
                    response.ContentType = "text/plain; charset=utf-8";
                    byte[] content = Encoding.UTF8.GetBytes(voiceText);

                    response.OutputStream.Write(content, 0, content.Length);
                    OneShotPlayMode(voiceName, engineName, voiceText, ep);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
                finally

                {
                    response.Close();
                }
            }
        }