/// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice = PlayDevices.Both,
            bool isSync            = false,
            float?volume           = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // テキストをユーザ辞書で置き換える
            text = this.ReplaceByUserDictionary(text);

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                this.Config.ToString());

            lock (this)
            {
                if (!File.Exists(wave))
                {
                    this.CreateWave(
                        text,
                        wave);
                }
            }

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
        }
Example #2
0
 /// <summary>
 /// TTSに話してもらう
 /// </summary>
 /// <param name="text">読上げるテキスト</param>
 public void Speak(
     string text,
     PlayDevices playDevice     = PlayDevices.Both,
     VoicePalettes voicePalette = VoicePalettes.Default,
     bool isSync  = false,
     float?volume = null)
 => SpeechController.instance.Speak(text, playDevice, voicePalette, isSync, volume);
Example #3
0
        public void PlaySound(
            string wave,
            PlayDevices playDevice = PlayDevices.Both,
            bool isSync            = false,
            float?volume           = null)
        {
            if (!File.Exists(wave))
            {
                return;
            }

            if (!isSync)
            {
                Task.Run(() => SoundPlayerWrapper.Play(wave, playDevice, isSync, volume));
            }
            else
            {
                Task.Run(() =>
                {
                    lock (WaveBlocker)
                    {
                        SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
                    }
                });
            }
        }
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                Settings.Default.SasaraSettings.ToString());

            this.CreateWaveWrapper(wave, () =>
            {
                // 音声waveファイルを生成する
                Settings.Default.SasaraSettings.SetToRemote();
                RemoteTTSClient.Instance.TTSModel.TextToWave(
                    TTSTypes.CeVIO,
                    text,
                    wave,
                    0,
                    Settings.Default.SasaraSettings.Gain);
            });

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
        }
Example #5
0
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice = PlayDevices.Both)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                Settings.Default.SasaraSettings.ToString());

            lock (this)
            {
                if (!File.Exists(wave))
                {
                    // 音声waveファイルを生成する
                    RemoteTTSClient.Instance.TTSModel.TextToWave(
                        TTSTypes.CeVIO,
                        text,
                        wave,
                        0,
                        Settings.Default.SasaraSettings.Gain);
                }
            }

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice);
        }
Example #6
0
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice = PlayDevices.Both,
            bool isSync            = false)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                Settings.Default.PollySettings.ToString(),
                true);

            lock (this)
            {
                if (!File.Exists(wave))
                {
                    this.CreateWave(
                        text,
                        wave);
                }
            }

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync);
        }
        public static void SpeakWithDelay(
            this ISpeechController speechController,
            string text,
            double delay,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            if (delay == 0d)
            {
                speechController.Speak(text, playDevice, isSync, volume);
                return;
            }

            var timer = new Timer(new TimerCallback((state) =>
            {
                speechController.Speak(text, playDevice, isSync);
                (state as Timer).Dispose();
            }));

            timer.Change(
                TimeSpan.FromSeconds(delay),
                TimeSpan.Zero);
        }
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                Settings.Default.PollySettings.ToString(),
                true);

            this.CreateWaveWrapper(wave, () =>
            {
                this.CreateWave(
                    text,
                    wave);
            });

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
        }
        public void Speak(
            string message,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            // ファイルじゃない(TTS)?
            if (!message.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) &&
                !message.EndsWith(".wave", StringComparison.OrdinalIgnoreCase) &&
                !message.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase))
            {
                if (!isSync)
                {
                    Task.Run(() => this.SpeakTTS(message, playDevice, voicePalette, isSync, volume));
                }
                else
                {
                    Task.Run(() =>
                    {
                        lock (TTSBlocker)
                        {
                            this.SpeakTTS(message, playDevice, voicePalette, isSync, volume);
                        }
                    });
                }

                return;
            }

            // waveファイルとして再生する
            var wave = message;

            if (!File.Exists(wave))
            {
                var dirs = new string[]
                {
                    Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"resources\wav"),
                    Path.Combine(this.PluginDirectory, @"resources\wav"),
                };

                foreach (var dir in dirs)
                {
                    var f = Path.Combine(dir, wave);
                    if (File.Exists(f))
                    {
                        wave = f;
                        break;
                    }
                }
            }

            // Volume はダミーなので0で指定する
            this.PlaySound(wave, playDevice, isSync, volume);
        }
 public static void SpeakWithDelay(
     this ISpeechController speechController,
     string text,
     double delay,
     PlayDevices playDevice = PlayDevices.Both,
     bool isSync            = false,
     float?volume           = null)
 => SpeakWithDelay(speechController, text, delay, playDevice, VoicePalettes.Default, isSync, volume);
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            HOYAConfig config;

            switch (voicePalette)
            {
            case VoicePalettes.Default:
                config = Settings.Default.HOYASettings;
                break;

            case VoicePalettes.Ext1:
                config = Settings.Default.HOYASettingsExt1;
                break;

            case VoicePalettes.Ext2:
                config = Settings.Default.HOYASettingsExt2;
                break;

            default:
                config = Settings.Default.HOYASettings;
                break;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                config.ToString());

            this.CreateWaveWrapper(wave, () =>
            {
                if (string.IsNullOrWhiteSpace(
                        Settings.Default.HOYASettings.APIKey))
                {
                    return;
                }

                this.CreateWave(
                    text,
                    config,
                    wave);
            });

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
        }
        public static void Play(
            string waveFile,
            PlayDevices playDevice = PlayDevices.Both,
            bool isSync            = false,
            float?volume           = null)
        {
            if (!volume.HasValue)
            {
                volume = Settings.Default.WaveVolume / 100.0f;
            }

            switch (playDevice)
            {
            case PlayDevices.Both:
                if (Settings.Default.EnabledSubDevice &&
                    !string.IsNullOrEmpty(Settings.Default.SubDeviceID))
                {
                    SoundPlayerWrapper.PlayCore(
                        waveFile,
                        volume.Value,
                        Settings.Default.Player,
                        Settings.Default.SubDeviceID,
                        isSync);
                }

                SoundPlayerWrapper.PlayCore(
                    waveFile,
                    volume.Value,
                    Settings.Default.Player,
                    Settings.Default.MainDeviceID,
                    isSync);
                break;

            case PlayDevices.Main:
                SoundPlayerWrapper.PlayCore(
                    waveFile,
                    volume.Value,
                    Settings.Default.Player,
                    Settings.Default.MainDeviceID,
                    isSync);
                break;

            case PlayDevices.Sub:
                if (Settings.Default.EnabledSubDevice &&
                    !string.IsNullOrEmpty(Settings.Default.SubDeviceID))
                {
                    SoundPlayerWrapper.PlayCore(
                        waveFile,
                        volume.Value,
                        Settings.Default.Player,
                        Settings.Default.SubDeviceID,
                        isSync);
                }
                break;
            }
        }
Example #13
0
        private void SpeakTTS(
            string textToSpeak,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            const string waitCommand = "/wait";

            try
            {
                // waitなし?
                if (!textToSpeak.StartsWith(waitCommand))
                {
                    SpeechController.Default.Speak(textToSpeak, playDevice, voicePalette, isSync, volume);
                }
                else
                {
                    var values = textToSpeak.Split(',');

                    // 分割できない?
                    if (values.Length < 2)
                    {
                        // 普通に読上げて終わる
                        SpeechController.Default.Speak(textToSpeak, playDevice, voicePalette, isSync, volume);
                        return;
                    }

                    var command = values[0].Trim();
                    var message = values[1].Trim();

                    // 秒数を取り出す
                    var delayAsText = command.Replace(waitCommand, string.Empty);
                    int delay       = 0;
                    if (!int.TryParse(delayAsText, out delay))
                    {
                        // 普通に読上げて終わる
                        SpeechController.Default.Speak(textToSpeak, playDevice, voicePalette, isSync, volume);
                        return;
                    }

                    // ディレイをかけて読上げる
                    SpeechController.Default.SpeakWithDelay(
                        message,
                        delay,
                        playDevice,
                        isSync,
                        volume);
                }
            }
            catch (Exception ex)
            {
                this.Logger.Error(ex, "SpeakTTS で例外が発生しました。");
            }
        }
Example #14
0
        public void PlaySound(
            string wave,
            int volume,
            PlayDevices playDevice = PlayDevices.Both)
        {
            if (!File.Exists(wave))
            {
                return;
            }

            Task.Run(() => SoundPlayerWrapper.Play(wave, playDevice));
        }
Example #15
0
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice = PlayDevices.Both,
            bool isSync            = false,
            float?volume           = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text,
                this.Config.ToString());

            lock (this)
            {
                if (!File.Exists(wave))
                {
                    using (var fs = new FileStream(wave, FileMode.Create))
                        using (var synth = new SpeechSynthesizer())
                        {
                            // VOICEを設定する
                            var voice = this.GetSynthesizer(this.Config.VoiceID);
                            if (voice == null)
                            {
                                return;
                            }

                            synth.SelectVoice(voice.VoiceInfo.Name);

                            synth.Rate   = this.Config.Rate;
                            synth.Volume = this.Config.Volume;

                            // Promptを生成する
                            var pb = new PromptBuilder(voice.VoiceInfo.Culture);
                            pb.StartVoice(voice.VoiceInfo);
                            pb.AppendSsmlMarkup(
                                $"<prosody pitch=\"{this.Config.Pitch.ToXML()}\">{text}</prosody>");
                            pb.EndVoice();

                            synth.SetOutputToWaveStream(fs);
                            synth.Speak(pb);
                        }
                }
            }

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
        }
Example #16
0
        /// <summary>
        /// 空になった旨を発言する
        /// </summary>
        /// <param name="targetStatus">
        /// 対象のステータス HP/MP/TP</param>
        /// <param name="pcName">
        /// PC名</param>
        private void SpeakEmpty(
            string targetStatus,
            string pcName,
            PlayDevices device         = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default)
        {
            var emptyJa = $"{pcName},{targetStatus}なし。";
            var emptyEn = $"{pcName}, {targetStatus} empty.";
            var diedJa  = $"{pcName},戦闘不能。";
            var diedEn  = $"{pcName}, dead.";
            var fullJa  = $"{pcName},{targetStatus}満タン。";
            var fullEn  = $"{pcName},{targetStatus} full.";

            var empty = string.Empty;
            var died  = string.Empty;
            var full  = string.Empty;

            switch (Settings.Default.UILocale)
            {
            case Locales.EN:
                empty = emptyEn;
                died  = diedEn;
                full  = fullJa;
                break;

            case Locales.JA:
                empty = emptyJa;
                died  = diedJa;
                full  = fullEn;
                break;
            }

            var tts = string.Empty;

            switch (targetStatus.ToUpper())
            {
            case "HP":
                tts = died;
                break;

            case "GP":
                tts = full;
                break;

            default:
                tts = empty;
                break;
            }

            this.Speak(tts, device, voicePalette);
        }
        private void SpeakTTS(
            string textToSpeak,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            try
            {
                if (!textToSpeak.ContainsIgnoreCase("/wait"))
                {
                    SpeechController.Default.Speak(textToSpeak, playDevice, voicePalette, isSync, volume);
                    return;
                }

                var match = WaitCommandRegex.Match(textToSpeak);
                if (!match.Success)
                {
                    SpeechController.Default.Speak(textToSpeak, playDevice, voicePalette, isSync, volume);
                    return;
                }

                var delayAsText = match.Groups["due"].Value;
                var message     = match.Groups["tts"].Value?.Trim();

                if (!double.TryParse(delayAsText, out double delay))
                {
                    // 普通に読上げて終わる
                    SpeechController.Default.Speak(textToSpeak, playDevice, voicePalette, isSync, volume);
                    return;
                }

                if (string.IsNullOrEmpty(message))
                {
                    return;
                }

                // ディレイをかけて読上げる
                SpeechController.Default.SpeakWithDelay(
                    message,
                    delay,
                    playDevice,
                    isSync,
                    volume);
            }
            catch (Exception ex)
            {
                this.Logger.Error(ex, "SpeakTTS で例外が発生しました。");
            }
        }
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice = PlayDevices.Both,
            bool isSync            = false,
            float?volume           = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                Settings.Default.YukkuriSettings.ToString());

            lock (this)
            {
                if (!File.Exists(wave))
                {
                    // よみがなに変換する
                    var tts = text;

                    if (Settings.Default.YukkuriSettings.UseKanji2Koe)
                    {
                        tts = this.ConvertToPhoneticByKanji2Koe(tts);
                    }
                    else
                    {
                        tts = this.ConvertToPhonetic(tts);
                    }

                    this.GetLogger()?.Trace($"Yukkuri speak={text}, phonetic={tts}");

                    // WAVEを生成する
                    AquesTalk.Instance.TextToWave(
                        tts,
                        wave,
                        Settings.Default.YukkuriSettings.ToParameter());
                }
            }

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
        }
        public static void Play(
            string waveFile,
            PlayDevices playDevice = PlayDevices.Both)
        {
            var volume = Settings.Default.WaveVolume / 100f;

            switch (playDevice)
            {
            case PlayDevices.Both:
                if (Settings.Default.EnabledSubDevice)
                {
                    SoundPlayerWrapper.PlayCore(
                        waveFile,
                        volume,
                        Settings.Default.Player,
                        Settings.Default.SubDeviceID);
                }

                SoundPlayerWrapper.PlayCore(
                    waveFile,
                    volume,
                    Settings.Default.Player,
                    Settings.Default.MainDeviceID);
                break;

            case PlayDevices.Main:
                SoundPlayerWrapper.PlayCore(
                    waveFile,
                    volume,
                    Settings.Default.Player,
                    Settings.Default.MainDeviceID);
                break;

            case PlayDevices.Sub:
                if (Settings.Default.EnabledSubDevice)
                {
                    SoundPlayerWrapper.PlayCore(
                        waveFile,
                        volume,
                        Settings.Default.Player,
                        Settings.Default.SubDeviceID);
                }
                break;
            }
        }
 /// <summary>
 /// テキストを読み上げる
 /// </summary>
 /// <param name="text">読み上げるテキスト</param>
 public void Speak(
     string text,
     PlayDevices playDevice = PlayDevices.Both)
 {
     Task.Run(() =>
     {
         try
         {
             lock (this)
             {
                 this.SpeakCore(text);
             }
         }
         catch (Exception ex)
         {
             this.GetLogger().Error(ex, "棒読みちゃんの読上げで例外が発生しました。");
         }
     });
 }
Example #21
0
        public void Speak(
            string message,
            PlayDevices playDevice = PlayDevices.Both)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            // ファイルじゃない(TTS)?
            if (!message.EndsWith(".wav") &&
                !message.EndsWith(".wave"))
            {
                Task.Run(() => this.SpeakTTS(message, playDevice));
                return;
            }

            // waveファイルとして再生する
            var wave = message;

            if (!File.Exists(wave))
            {
                var dirs = new string[]
                {
                    Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"resources\wav"),
                    Path.Combine(this.PluginDirectory, @"resources\wav"),
                };

                foreach (var dir in dirs)
                {
                    var f = Path.Combine(dir, wave);
                    if (File.Exists(f))
                    {
                        wave = f;
                        break;
                    }
                }
            }

            // Volumeはダミーなので0で指定する
            this.PlaySound(wave, 0, playDevice);
        }
Example #22
0
        public static void SpeakWithDelay(
            this ISpeechController speechController,
            string text,
            int delay,
            PlayDevices playDevice = PlayDevices.Both)
        {
            if (delay == 0)
            {
                speechController.Speak(text, playDevice);
                return;
            }

            var timer = new Timer(new TimerCallback((state) =>
            {
                speechController.Speak(text, playDevice);
                (state as Timer).Dispose();
            }));

            timer.Change(
                delay * 1000,
                0);
        }
Example #23
0
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        /// <param name="isSync">使用しない</param>
        /// <param name="playDevice">使用しない</param>
        /// <param name="voicePalette">使用しない</param>
        /// <param name="volume">使用しない</param>
        public void Speak(
            string text,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            if (this.lastText == text &&
                (DateTime.Now - this.lastTextTimestamp).TotalSeconds
                <= Settings.Default.GlobalSoundInterval)
            {
                return;
            }

            this.lastText          = text;
            this.lastTextTimestamp = DateTime.Now;

            this.Queue.Enqueue(text.Trim());
        }
Example #24
0
 /// <summary>
 /// スピーク
 /// </summary>
 /// <param name="textToSpeak">喋る文字列</param>
 public void Speak(
     string textToSpeak,
     PlayDevices device = PlayDevices.Both,
     bool isSync        = false) =>
 Speak(textToSpeak, device, VoicePalettes.Default, isSync);
Example #25
0
 /// <summary>
 /// スピーク
 /// </summary>
 /// <param name="textToSpeak">喋る文字列</param>
 public void Speak(
     string textToSpeak,
     PlayDevices device = PlayDevices.Both,
     bool isSync        = false) =>
 this.SpeakDelegate?.Invoke(textToSpeak, device, isSync);
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public void Speak(
            string text,
            PlayDevices playDevice = PlayDevices.Both,
            bool isSync            = false,
            float?volume           = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            var client = GoogleCloudTextToSpeechConfig.TTSClient;

            if (client == null)
            {
                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text.Replace(Environment.NewLine, "+"),
                Settings.Default.GoogleCloudTextToSpeechSettings.ToString());

            this.CreateWaveWrapper(wave, () =>
            {
                // 合成する音声のパラメーターを設定する
                SynthesisInput input = new SynthesisInput
                {
                    Text = text
                };

                VoiceSelectionParams voice = new VoiceSelectionParams
                {
                    LanguageCode = Settings.Default.GoogleCloudTextToSpeechSettings.LanguageCode,
                    Name         = Settings.Default.GoogleCloudTextToSpeechSettings.Name,
                };

                AudioConfig config = new AudioConfig
                {
                    AudioEncoding   = AudioEncoding.Linear16,
                    VolumeGainDb    = Settings.Default.GoogleCloudTextToSpeechSettings.VolumeGainDb,
                    Pitch           = Settings.Default.GoogleCloudTextToSpeechSettings.Pitch,
                    SpeakingRate    = Settings.Default.GoogleCloudTextToSpeechSettings.SpeakingRate,
                    SampleRateHertz = Settings.Default.GoogleCloudTextToSpeechSettings.SampleRateHertz,
                };

                // 音声合成リクエストを送信する
                var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest
                {
                    Input       = input,
                    Voice       = voice,
                    AudioConfig = config
                });

                // 合成した音声をファイルに書き出す
                using (Stream output = File.Create(wave))
                {
                    response.AudioContent.WriteTo(output);
                }
            });

            // 再生する
            SoundPlayerWrapper.Play(wave, playDevice, isSync, volume);
        }
Example #27
0
 /// <summary>
 /// スピーク
 /// </summary>
 /// <param name="textToSpeak">喋る文字列</param>
 public void Speak(
     string textToSpeak,
     PlayDevices device         = PlayDevices.Both,
     VoicePalettes voicePalette = VoicePalettes.Default,
     bool isSync = false) =>
 this.SpeakDelegate?.Invoke(textToSpeak, device, voicePalette, isSync);
Example #28
0
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public async void Speak(
            string text,
            PlayDevices playDevice = PlayDevices.Both)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // 起動していなければ起動させる
            var err = await this.Start();

            if (!string.IsNullOrEmpty(err))
            {
                this.GetLogger().Error($"VOICEROID Speeak error text={text}, err={err}");
                return;
            }

            var process = this.Config.GetSelected()?.InnerProcess;

            if (process == null)
            {
                return;
            }

            // アクティブにさせないようにする
            this.SetNotActiveWindow(process.MainWindowHandle);

            if (this.Config.DirectSpeak)
            {
                // 直接再生する
                if (await process.SetTalkText(text))
                {
                    if (!await process.Play())
                    {
                        this.GetLogger().Error($"VOICEROID Speeak error text={text}");
                        return;
                    }
                }

                return;
            }

            // 現在の条件をハッシュ化してWAVEファイル名を作る
            var wave = this.GetCacheFileName(
                Settings.Default.TTS,
                text,
                this.Config.ToString());

            if (!File.Exists(wave))
            {
                // 音声waveファイルを生成する
                if (await process.SetTalkText(text))
                {
                    var result = await process.Save(wave);

                    if (!result.IsSucceeded)
                    {
                        this.GetLogger().Error($"VOICEROID Speeak error text={text}, err={result.Error}, extra={result.ExtraMessage}");
                        return;
                    }
                }
            }

            // 再生する
            SoundPlayerWrapper.Play(wave);
        }
 /// <summary>
 /// テキストを読み上げる
 /// </summary>
 /// <param name="text">読み上げるテキスト</param>
 public void Speak(
     string text,
     PlayDevices playDevice = PlayDevices.Both,
     bool isSync            = false,
     float?volume           = null)
 => Speak(text, playDevice, VoicePalettes.Default, isSync, volume);
 private void SpeakTTS(
     string textToSpeak,
     PlayDevices playDevice = PlayDevices.Both,
     bool isSync            = false,
     float?volume           = null)
 => SpeakTTS(textToSpeak, playDevice, VoicePalettes.Default, isSync, volume);