Beispiel #1
0
        public SpeechSynth()
        {
            _speechSynthData = new SpeechSynthData();
            UriBuilder uri = new UriBuilder(Assembly.GetExecutingAssembly().CodeBase);
            _speechSynthDir = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)) + "\\VSTalker\\";
            _speechSynthConfigFilePath = _speechSynthDir + "default.vstalker";

            if (!Directory.Exists(_speechSynthDir))
                Directory.CreateDirectory(_speechSynthDir);

            if (File.Exists(_speechSynthConfigFilePath))
                LoadConfig(_speechSynthConfigFilePath);
            else
                _mustSave = true;
            foreach (InstalledVoice voice in _speechSynthesizer.GetInstalledVoices())
            {
                VoiceInfo info = voice.VoiceInfo;
                SpeechVoice speechVoice = GetSpeechVoiceByName(info.Name);
                if (speechVoice == null)
                {
                    speechVoice = new SpeechVoice(info.Name);
                    lock (_speechSynthData._speechVoiceList)
                    {
                        _speechSynthData._speechVoiceList.Add(speechVoice);
                    }
                    _mustSave = true;
                }
            }

            if (_mustSave)
                SaveConfig(_speechSynthConfigFilePath);
        }
Beispiel #2
0
 public void SetVoice(string voiceName)
 {
     if (_isPlaying)
     {
         _isPlaying = false;
         Task.Delay(1000).ContinueWith(t => {
             SetVoice(voiceName);
         });
         return;
     }
     _lockPlay = true;
     lock (_speechSynthData._speechVoiceList)
     {
         foreach (SpeechVoice sV in _speechSynthData._speechVoiceList)
         {
             if (sV._voiceName == voiceName)
             {
                 _currentSpeechVoice = sV;
                 _mustSave = true;
                 break;
             }
         }
     }
     SetPhonem(_speechSynthData._isPhonem);
     _lockPlay = false;
 }