Пример #1
0
        public override Task <Task> Handle(RegisterProfileCommand command, CancellationToken cancellationToken = default)
        {
            var profileOptions = new CredentialProfileOptions
            {
                SourceProfile = command.Profile.SourceProfile,
                RoleArn       = command.Profile.RoleArn,
                AccessKey     = command.AccessKey,
                SecretKey     = command.SecretKey
            };

            var credentialProfile = new CredentialProfile(command.Profile.Name, profileOptions);

            _credentialProfileStoreChain.RegisterProfile(credentialProfile);

            return(Task.FromResult(Task.CompletedTask));
        }
Пример #2
0
        /// <summary>
        /// Creates the AWS Credentials profile.
        /// </summary>
        /// <returns><c>true</c>, if AWSC redentials profile was created, <c>false</c> otherwise.</returns>
        public static bool CreateAWSCredentialsProfile()
        {
            var options = new CredentialProfileOptions
            {
                AccessKey = "YOUR_AWS_ACCESS_KEY_ID",
                SecretKey = "YOUR_AWS_SECRET_ACCESS_KEY"
            };
            var profile = new CredentialProfile("basic_profile", options)
            {
                Region = RegionEndpoint.USWest2
            };
            var credentialProfileStoreChain = new CredentialProfileStoreChain();

            credentialProfileStoreChain.RegisterProfile(profile);
            return(true);
        }
Пример #3
0
        /// <summary>
        /// WAVEファイルを生成する
        /// </summary>
        /// <param name="textToSpeak">
        /// Text to Speak</param>
        /// <param name="wave">
        /// WAVEファイルのパス</param>
        private void CreateWave(
            string textToSpeak,
            string wave)
        {
            var config   = Settings.Default.PollySettings;
            var endpoint = config.Endpoint;
            var chain    = new CredentialProfileStoreChain();

            var hash        = (config.Region + config.AccessKey + config.SecretKey).GetHashCode().ToString("X4");
            var profileName = $"polly_profile_{hash}";

            AWSCredentials awsCredentials;

            if (!chain.TryGetAWSCredentials(
                    profileName,
                    out awsCredentials))
            {
                var options = new CredentialProfileOptions
                {
                    AccessKey = config.AccessKey,
                    SecretKey = config.SecretKey,
                };

                var profile = new CredentialProfile(profileName, options);
                profile.Region = endpoint;

                chain.RegisterProfile(profile);

                chain.TryGetAWSCredentials(
                    profileName,
                    out awsCredentials);
            }

            if (awsCredentials == null)
            {
                return;
            }

            using (var pc = new AmazonPollyClient(
                       awsCredentials,
                       endpoint))
            {
                var ssml =
                    $@"<speak><prosody volume=""{config.Volume.ToXML()}"" rate=""{config.Rate.ToXML()}"" pitch=""{config.Pitch.ToXML()}"">{textToSpeak}</prosody></speak>";

                var req = new SynthesizeSpeechRequest();
                req.TextType     = TextType.Ssml;
                req.Text         = ssml;
                req.OutputFormat = OutputFormat.Mp3;
                req.VoiceId      = config.Voice;

                var res = pc.SynthesizeSpeech(req);

                using (var fs = new FileStream(wave, FileMode.Create, FileAccess.Write))
                {
                    res.AudioStream.CopyTo(fs);
                    fs.Flush();
                    fs.Close();
                }
            }
        }
Пример #4
0
        private async void ExecuteGetVoicesCommand()
        {
            if (string.IsNullOrEmpty(this.Config.AccessKey) ||
                string.IsNullOrEmpty(this.Config.SecretKey))
            {
                ModernMessageBox.ShowDialog(
                    "Enter your access key and secret key.",
                    "ACT.Hojoring");

                return;
            }

            var endpoint = this.Config.Endpoint;
            var chain    = new CredentialProfileStoreChain();

            var hash        = (this.Config.Region + this.Config.AccessKey + this.Config.SecretKey).GetHashCode().ToString("X4");
            var profileName = $"polly_profile_{hash}";

            AWSCredentials awsCredentials;

            if (!chain.TryGetAWSCredentials(
                    profileName,
                    out awsCredentials))
            {
                var options = new CredentialProfileOptions
                {
                    AccessKey = this.Config.AccessKey,
                    SecretKey = this.Config.SecretKey,
                };

                var profile = new CredentialProfile(profileName, options);
                profile.Region = endpoint;

                chain.RegisterProfile(profile);

                chain.TryGetAWSCredentials(
                    profileName,
                    out awsCredentials);
            }

            if (awsCredentials == null)
            {
                return;
            }

            var voice = this.Config.Voice;

            using (var pc = new AmazonPollyClient(
                       awsCredentials,
                       endpoint))
            {
                var res = await pc.DescribeVoicesAsync(new DescribeVoicesRequest());

                if (res == null ||
                    res.HttpStatusCode != HttpStatusCode.OK)
                {
                    ModernMessageBox.ShowDialog(
                        "Voices update is failed.",
                        "ACT.Hojoring");

                    return;
                }

                this.Voices.Clear();
                this.Config.Voice = string.Empty;

                foreach (var v in
                         from x in res.Voices
                         orderby
                         x.LanguageCode.ToString(),
                         x.Gender.ToString(),
                         x.Name
                         select
                         x)
                {
                    this.Voices.Add(
                        new PollyConfigs.PollyVoice {
                        Name = $"{v.Id.Value} ({v.LanguageCode}, {v.Gender})", Value = v.Id
                    });
                }
            }

            if (this.Voices.Any(x => x.Value == voice))
            {
                this.Config.Voice = voice;
            }

            Settings.Default.Save();

            ModernMessageBox.ShowDialog(
                "Voices update is completed.",
                "ACT.Hojoring");
        }