public GoogleCloudTextToSpeechConfigView(VoicePalettes voicePalette = VoicePalettes.Default)
        {
            this.InitializeComponent();
            this.DataContext = new GoogleCloudTextToSpeechConfigViewModel(voicePalette);

            this.SetLocale(Settings.Default.UILocale);
        }
        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);
        }
Example #5
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 #6
0
        public HoyaConfigView(VoicePalettes voicePalette = VoicePalettes.Default)
        {
            InitializeComponent();
            this.DataContext = new HoyaConfigViewModel(voicePalette);

            this.SetLocale(Settings.Default.UILocale);
        }
        /// <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);
        }
        /// <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);
        }
Example #9
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 #10
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 で例外が発生しました。");
            }
        }
Example #12
0
        /// <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,
                this.Config.ToString());

            this.CreateWaveWrapper(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);
        }
        /// <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.YukkuriSettings.ToString());

            this.CreateWaveWrapper(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);
        }
Example #14
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());
        }
        /// <summary>
        /// テキストを読み上げる
        /// </summary>
        /// <param name="text">読み上げるテキスト</param>
        public async void Speak(
            string text,
            PlayDevices playDevice     = PlayDevices.Both,
            VoicePalettes voicePalette = VoicePalettes.Default,
            bool isSync  = false,
            float?volume = null)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

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

            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, playDevice, isSync, volume);
        }
Example #16
0
 public YukkuriConfigViewModel(VoicePalettes voicePalette = VoicePalettes.Default)
 {
     this.VoicePalette = voicePalette;
 }
Example #17
0
 public void PlayMain(string message, VoicePalettes voicePalette, bool isSync) =>
 this.PlayMainDeviceDelegate?.Invoke(message, voicePalette, isSync, null);
Example #18
0
 public void PlayMain(string message, VoicePalettes voicePalette, bool isSync, float?volume) =>
 this.PlayMainDeviceDelegate?.Invoke(message, voicePalette, 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;
            }

            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 #20
0
 public OpenJTalkConfigViewModel(VoicePalettes voicePalette = VoicePalettes.Default)
 {
     this.VoicePalette = voicePalette;
 }
Example #21
0
 public HoyaConfigViewModel(VoicePalettes voicePalette = VoicePalettes.Default)
 {
     this.VoicePalette = voicePalette;
 }
Example #22
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 #23
0
 public GoogleCloudTextToSpeechConfigViewModel(VoicePalettes voicePalette = VoicePalettes.Default)
 {
     this.VoicePalette = voicePalette;
 }