Ejemplo n.º 1
0
        private bool SpeakToFile(string[] splitData, string filePath)
        {
            if (!tmpVoicesAllocations.ContainsKey(splitData[1]))
            {
                // get random voice from selected voices by gender
                Voice[] voices    = GetSelectedVoices();
                Gender  gender    = (splitData[0] == "f") ? Gender.Female : Gender.Male;                      // get gender
                Voice[] genVoices = Array.FindAll(voices, delegate(Voice v) { return(v.Gender == gender); }); // find voices by gender
                genVoices = genVoices.Length == 0 ? voices : genVoices;                                       // if no voice for gender selected select ay
                tmpVoicesAllocations.Add(splitData[1], genVoices[new Random().Next(genVoices.Length)]);       // allocate voice to npcid
            }

            Voice voice = tmpVoicesAllocations[splitData[1]];

            string err = null;

            switch (voice.Module)
            {
            case Module.Windows:
                err = WindowsTTS.Speak(splitData[2], voice, filePath);
                break;

            case Module.Azure:
                err = AzureTTS.Speak(splitData[2], voice, filePath, config.AzureAPI);
                break;

            case Module.Google:
                err = GoogleTTS.Speak(splitData[2], voice, filePath);
                break;

            case Module.AWS:
                err = AwsTTS.Speak(splitData[2], voice, filePath, config.AwsAPI);
                break;
            }

            if (err != null)
            {
                OnError(err);
                return(false);
            }

            OnSpeechPrepare(voice);

            return(true);
        }
        private void VoiceTestSpeak(string txt, QuestToSpeech.Voice voice)
        {
            string err   = null;
            string fPath = Path.Combine(QuestToSpeech.TempDirectory, string.Format("test-{0}.wav", Util.MD5Hash(testString + voice.Name + voice.Module)));

            if (!File.Exists(fPath))
            {
                if (voice.Module == QuestToSpeech.Module.Windows)
                {
                    err = WindowsTTS.Speak(testString, voice, fPath);
                }
                else if (voice.Module == QuestToSpeech.Module.Azure)
                {
                    err = AzureTTS.Speak(testString, voice, fPath, azureAPIConfig);
                }
                else if (voice.Module == QuestToSpeech.Module.Google)
                {
                    err = GoogleTTS.Speak(testString, voice, fPath);
                }
                else if (voice.Module == QuestToSpeech.Module.AWS)
                {
                    err = AwsTTS.Speak(testString, voice, fPath, awsAPIConfig);
                }
            }

            if (err != null)
            {
                MessageBox.Show(err);
                return;
            }

            if (File.Exists(fPath))
            {
                if (player != null)
                {
                    player.Stop();
                    player.Dispose();
                }

                player = new SoundPlayer(fPath);
                player.Play();
            }
        }
Ejemplo n.º 3
0
        public Voice[] GetAvailableVoices()
        {
            if (cachedAvailableVoices != null)
            {
                return(cachedAvailableVoices);
            }

            List <Voice> voices = new List <Voice>();

            if (config.EnabledModules.Contains(Module.Windows))
            {
                Voice[] arr = new Voice[0];

                string err = WindowsTTS.GetVoices(ref arr);

                if (err != null)
                {
                    OnError(err);
                    return(null);
                }
                else
                {
                    voices.AddRange(arr);
                }
            }

            if (config.EnabledModules.Contains(Module.Azure))
            {
                Voice[] arr = new Voice[0];

                string err = AzureTTS.GetVoices(ref arr, config.AzureAPI);

                if (err != null)
                {
                    OnError(err);
                    return(null);
                }
                else
                {
                    voices.AddRange(arr);
                }
            }

            if (config.EnabledModules.Contains(Module.Google))
            {
                Voice[] arr = new Voice[0];

                string err = GoogleTTS.GetVoices(ref arr);

                if (err != null)
                {
                    OnError(err);
                    return(null);
                }
                else
                {
                    voices.AddRange(arr);
                }
            }

            if (config.EnabledModules.Contains(Module.AWS))
            {
                Voice[] arr = new Voice[0];

                string err = AwsTTS.GetVoices(ref arr, config.AwsAPI);

                if (err != null)
                {
                    OnError(err);
                    return(null);
                }
                else
                {
                    voices.AddRange(arr);
                }
            }

            cachedAvailableVoices = voices.ToArray();             // cache list

            return(cachedAvailableVoices);
        }