コード例 #1
0
 public QuestToSpeechConfig()           // set defaults
 {
     EnabledModules = new QuestToSpeech.Module[] { QuestToSpeech.Module.Windows };
     SelectedVoices = new QuestToSpeech.Voice[0];
     AzureAPI       = null;
     AwsAPI         = null;
 }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtAzureKey.Text) && comboAzureRegion.SelectedIndex != -1)
            {
                AzureAPIConfig = new AzureAPIConfig()
                {
                    Key    = txtAzureKey.Text.Trim(),
                    Region = comboAzureRegion.SelectedItem.ToString()
                };
            }
            else
            {
                AzureAPIConfig = null;
            }

            if (!string.IsNullOrWhiteSpace(txtAwsAccessKey.Text) && !string.IsNullOrWhiteSpace(txtAwsSecretKey.Text) && comboAwsRegion.SelectedIndex != -1)
            {
                AwsAPIConfig = new AwsAPIConfig()
                {
                    AccessKey = txtAwsAccessKey.Text.Trim(),
                    SecretKey = txtAwsSecretKey.Text.Trim(),
                    Region    = comboAwsRegion.SelectedItem.ToString()
                };
            }
            else
            {
                AwsAPIConfig = null;
            }
        }
コード例 #3
0
        public SettingsVoicesForm(QuestToSpeech.Voice[] allVoices, QuestToSpeech.Voice[] preSelected, AzureAPIConfig azureConfig, AwsAPIConfig awsConfig)
        {
            InitializeComponent();

            azureAPIConfig = azureConfig;
            awsAPIConfig   = awsConfig;

            voices = allVoices;
            tmpSelectedList.AddRange(preSelected);

            lblNumTotalSelected.Text = string.Format("(Total selected {0})", tmpSelectedList.Count);

            // insert voices
            foreach (QuestToSpeech.Voice v in voices)
            {
                if (!comboLangCodes.Items.Contains(v.LangCode))
                {
                    comboLangCodes.Items.Add(v.LangCode);
                }
            }
        }
コード例 #4
0
        public static string GetVoices(ref QuestToSpeech.Voice[] voices, AwsAPIConfig config)
        {
            List <QuestToSpeech.Voice> list = new List <QuestToSpeech.Voice>();

            try {
                using (AmazonPollyClient client = new AmazonPollyClient(config.AccessKey, config.SecretKey, Amazon.RegionEndpoint.GetBySystemName(config.Region))) {
                    DescribeVoicesRequest req = new DescribeVoicesRequest();
                    string nextToken;

                    do
                    {
                        DescribeVoicesResponse res = client.DescribeVoices(req);
                        nextToken     = res.NextToken;
                        req.NextToken = nextToken;

                        foreach (var voice in res.Voices)
                        {
                            list.Add(new QuestToSpeech.Voice()
                            {
                                Name     = string.Format("{0}-{1}", voice.LanguageCode, voice.Id.ToString()),
                                Gender   = voice.Gender == Gender.Female ? QuestToSpeech.Gender.Female : QuestToSpeech.Gender.Male,
                                LangCode = voice.LanguageCode,
                                Module   = QuestToSpeech.Module.AWS
                            });
                        }
                    } while (nextToken != null);

                    list.Sort(delegate(QuestToSpeech.Voice v1, QuestToSpeech.Voice v2) {
                        return(v1.Name.CompareTo(v2.Name));
                    });

                    voices = list.ToArray();
                }
            } catch (Exception ex) {
                return(ex.InnerException == null ? ex.Message : ex.InnerException.ToString());
            }

            return(null);
        }
コード例 #5
0
        public SettingsApisForm(AzureAPIConfig preAzureApiConfig, AwsAPIConfig preAwsApiConfig)
        {
            InitializeComponent();

            AzureAPIConfig = preAzureApiConfig;
            AwsAPIConfig   = preAwsApiConfig;

            if (AzureAPIConfig != null)
            {
                txtAzureKey.Text = AzureAPIConfig.Key;
                comboAzureRegion.SelectedItem = AzureAPIConfig.Region;
            }

            if (AwsAPIConfig != null)
            {
                txtAwsAccessKey.Text        = AwsAPIConfig.AccessKey;
                txtAwsSecretKey.Text        = AwsAPIConfig.SecretKey;
                comboAwsRegion.SelectedItem = AwsAPIConfig.Region;
            }

            if (Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS") == null)
            {
                lblGoogle.Text      = "Environment variable \"GOOGLE_APPLICATION_CREDENTIALS\" not found";
                lblGoogle.ForeColor = Color.Red;
            }
            else if (!File.Exists(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")))
            {
                lblGoogle.Text      = string.Format("Authentication file {0} not found", Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
                lblGoogle.ForeColor = Color.Red;
            }
            else
            {
                lblGoogle.Text      = "Environment variable and authentication file found";
                lblGoogle.ForeColor = Color.Green;
            }
        }
コード例 #6
0
 public void SetAwsAPIConfig(AwsAPIConfig apiConfig)
 {
     config.AwsAPI = apiConfig;
     SaveConfig();
 }
コード例 #7
0
        public static string Speak(string txt, QuestToSpeech.Voice voice, string filePath, AwsAPIConfig config)
        {
            try {
                using (AmazonPollyClient client = new AmazonPollyClient(config.AccessKey, config.SecretKey, Amazon.RegionEndpoint.GetBySystemName(config.Region))) {
                    string nameWoLang = voice.Name.Replace(voice.LangCode + "-", "");

                    SynthesizeSpeechRequest req = new SynthesizeSpeechRequest()
                    {
                        OutputFormat = OutputFormat.Mp3,
                        LanguageCode = voice.LangCode,
                        VoiceId      = (VoiceId)typeof(VoiceId).GetField(nameWoLang).GetValue(null),
                        Text         = txt
                    };

                    using (FileStream fileStream = new FileStream(filePath + ".mp3", FileMode.Create, FileAccess.Write)) {
                        SynthesizeSpeechResponse res = client.SynthesizeSpeech(req);
                        byte[] buffer = new byte[2 * 1024];
                        int    readBytes;

                        using (Stream audioStream = res.AudioStream) {
                            while ((readBytes = audioStream.Read(buffer, 0, 2 * 1024)) > 0)
                            {
                                fileStream.Write(buffer, 0, readBytes);
                            }
                        }
                    }

                    // convert to wav and delete mp3
                    if (File.Exists(filePath + ".mp3"))
                    {
                        using (Mp3FileReader mp3 = new Mp3FileReader(filePath + ".mp3")) {
                            using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3)) {
                                WaveFileWriter.CreateWaveFile(filePath, pcm);
                            }
                        }

                        File.Delete(filePath + ".mp3");
                    }
                }
            } catch (Exception ex) {
                return(ex.InnerException == null ? ex.Message : ex.InnerException.ToString());
            }

            return(null);
        }