Beispiel #1
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonPollyConfig config = new AmazonPollyConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonPollyClient client = new AmazonPollyClient(creds, config);

            ListSpeechSynthesisTasksResponse resp = new ListSpeechSynthesisTasksResponse();

            do
            {
                ListSpeechSynthesisTasksRequest req = new ListSpeechSynthesisTasksRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListSpeechSynthesisTasks(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.SynthesisTasks)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        /// <summary>
        /// Converts text to speech with the given voice and uploads audio file to S3.
        /// </summary>
        /// <param name="id">Post ID in DynamoDB</param>
        /// <param name="voiceId">Voice to be used in speech</param>
        /// <param name="text">Text to be converted</param>
        /// <returns>The file's URL in S3</returns>
        public async Task <string> ConvertAsync(string id, string voiceId, string text)
        {
            var pollyClient = new AmazonPollyClient();

            IEnumerable <string> textBlocks = TruncateText(text);

            foreach (string block in textBlocks)
            {
                var request = new SynthesizeSpeechRequest
                {
                    OutputFormat = OutputFormat.Mp3,
                    Text         = block,
                    VoiceId      = voiceId
                };

                try
                {
                    var response = await pollyClient.SynthesizeSpeechAsync(request);

                    WriteToFile(response.AudioStream, id);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(await UploadAsync(id));
        }
Beispiel #3
0
        public static void SynthesizeSpeech()
        {
            var    client         = new AmazonPollyClient();
            String outputFileName = "speech.mp3";

            var synthesizeSpeechRequest = new SynthesizeSpeechRequest()
            {
                OutputFormat = OutputFormat.Mp3,
                VoiceId      = VoiceId.Joanna,
                Text         = "This is a sample text to be synthesized."
            };

            try
            {
                using (var outputStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write))
                {
                    var    synthesizeSpeechResponse = client.SynthesizeSpeech(synthesizeSpeechRequest);
                    byte[] buffer = new byte[2 * 1024];
                    int    readBytes;

                    var inputStream = synthesizeSpeechResponse.AudioStream;
                    while ((readBytes = inputStream.Read(buffer, 0, 2 * 1024)) > 0)
                    {
                        outputStream.Write(buffer, 0, readBytes);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught: " + e.Message);
            }
        }
Beispiel #4
0
        public async Task <MemoryStream> PegaAudioPolly(string text)
        {
            AmazonPollyClient _amazonPolly = new AmazonPollyClient(RegionEndpoint.USEast1);

            try {
                var response = await _amazonPolly.SynthesizeSpeechAsync(new SynthesizeSpeechRequest
                {
                    OutputFormat = "mp3",
                    Text         = text,
                    TextType     = TextType.Text,
                    VoiceId      = VoiceId.Camila,
                    Engine       = Engine.Neural,
                });

                var retornoMemoryStream = new MemoryStream();
                response.AudioStream.CopyTo(retornoMemoryStream);

                return(retornoMemoryStream);
            }
            catch (Exception e)
            {
                Console.WriteLine("deu ruim");
            }

            return(null);
        }
Beispiel #5
0
        public PollyClient(string accessKey, string secretKey, RegionEndpoint region)
        {
            var credentials = new BasicAWSCredentials(accessKey, secretKey);

            this.client     = new AmazonPollyClient(credentials, region);
            this.soundQueue = new PollySoundQueue();
        }
Beispiel #6
0
        public static void TestPolly2()
        {
            using (AmazonPollyClient pc = new AmazonPollyClient())
            {
                SynthesizeSpeechRequest sreq = new SynthesizeSpeechRequest();
                sreq.Text         = "Your Sample Text Here 123";
                sreq.OutputFormat = OutputFormat.Mp3;
                sreq.VoiceId      = VoiceId.Salli;
                SynthesizeSpeechResponse sres = pc.SynthesizeSpeechAsync(sreq).GetAwaiter().GetResult();

                using (var memoryStream = new MemoryStream())
                {
                    sres.AudioStream.CopyTo(memoryStream);
                    memoryStream.Flush();

                    memoryStream.Position = 0;

                    string outputFile = @".\TestAudio\output-from-polly.wav";

                    using (Mp3FileReader reader = new Mp3FileReader(memoryStream))
                    {
                        using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader))
                        {
                            WaveFileWriter.CreateWaveFile(outputFile, pcmStream);
                        }
                    }
                }
            }
        }
        async public void getAudio(String text, String path)
        {
            AmazonPollyClient pc = new AmazonPollyClient(Amazon.RegionEndpoint.USEast1);

            SynthesizeSpeechRequest sreq = new SynthesizeSpeechRequest();

            sreq.Text         = text;
            sreq.OutputFormat = OutputFormat.Mp3;
            sreq.VoiceId      = VoiceId.Vitoria;
            sreq.SampleRate   = "8000";
            SynthesizeSpeechResponse sres = pc.SynthesizeSpeech(sreq);


            FileStream fileStream = File.Create(path);

            sres.AudioStream.CopyTo(fileStream);
            fileStream.Flush();
            fileStream.Close();
            FileStream fs = File.OpenRead(path);

            using (Mp3FileReader reader = new Mp3FileReader(fs))
            {
                var newFormat = new WaveFormat(8000, 16, 1);
                using (var converter = new WaveFormatConversionStream(newFormat, reader))
                {
                    var pathw = path + ".wav";
                    WaveFileWriter.CreateWaveFile(pathw, converter);
                }
            }
            fs.Dispose();
            File.Delete(path);
        }
Beispiel #8
0
        public static async Task Main()
        {
            string lexiconContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                    "<lexicon version=\"1.0\" xmlns=\"http://www.w3.org/2005/01/pronunciation-lexicon\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                                    "xsi:schemaLocation=\"http://www.w3.org/2005/01/pronunciation-lexicon http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd\" " +
                                    "alphabet=\"ipa\" xml:lang=\"en-US\">" +
                                    "<lexeme><grapheme>test1</grapheme><alias>test2</alias></lexeme>" +
                                    "</lexicon>";
            string lexiconName = "SampleLexicon";

            var client            = new AmazonPollyClient();
            var putLexiconRequest = new PutLexiconRequest()
            {
                Name    = lexiconName,
                Content = lexiconContent,
            };

            try
            {
                var response = await client.PutLexiconAsync(putLexiconRequest);

                if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    Console.WriteLine($"Successfully created Lexicon: {lexiconName}.");
                }
                else
                {
                    Console.WriteLine($"Could not create Lexicon: {lexiconName}.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught: " + ex.Message);
            }
        }
Beispiel #9
0
        public static void start(IModHelper h)
        {
            Helper      = h;
            currentText = "";
            tmppath     = Path.Combine(Path.Combine(Environment.CurrentDirectory, "Content"), "TTS");

            ensureFolderStructureExists(Path.Combine(tmppath, "speech.mp3"));
            pc              = AWSHandler.getPollyClient();
            currentVoice    = VoiceId.Amy;
            lastText        = "";
            lastDialog      = "";
            lastHud         = "";
            speak           = false;
            runSpeech       = true;
            currentCulture  = CultureInfo.CreateSpecificCulture("en-us");
            culturelang     = "en";
            installedVoices = new List <string>();


            setupVoices();
            setVoice("default");

            speechThread = new Thread(t2sOut);
            speechThread.Start();
            GameEvents.QuarterSecondTick += GameEvents_QuarterSecondTick;

            MenuEvents.MenuClosed += MenuEvents_MenuClosed;

            //ControlEvents.KeyPressed += ControlEvents_KeyPressed;
        }
        public static void PutLexicon()
        {
            String LEXICON_CONTENT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                     "<lexicon version=\"1.0\" xmlns=\"http://www.w3.org/2005/01/pronunciation-lexicon\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                                     "xsi:schemaLocation=\"http://www.w3.org/2005/01/pronunciation-lexicon http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd\" " +
                                     "alphabet=\"ipa\" xml:lang=\"en-US\">" +
                                     "<lexeme><grapheme>test1</grapheme><alias>test2</alias></lexeme>" +
                                     "</lexicon>";
            String LEXICON_NAME = "SampleLexicon";

            var client            = new AmazonPollyClient();
            var putLexiconRequest = new PutLexiconRequest()
            {
                Name    = LEXICON_NAME,
                Content = LEXICON_CONTENT
            };

            try
            {
                client.PutLexicon(putLexiconRequest);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught: " + e.Message);
            }
        }
Beispiel #11
0
        public static void ListLexicons()
        {
            var client = new AmazonPollyClient();

            var listLexiconsRequest = new ListLexiconsRequest();

            try
            {
                String nextToken;
                do
                {
                    var listLexiconsResponse = client.ListLexicons(listLexiconsRequest);
                    nextToken = listLexiconsResponse.NextToken;
                    listLexiconsResponse.NextToken = nextToken;

                    Console.WriteLine("All voices: ");
                    foreach (var lexiconDescription in listLexiconsResponse.Lexicons)
                    {
                        var attributes = lexiconDescription.Attributes;
                        Console.WriteLine("Name: " + lexiconDescription.Name
                                          + ", Alphabet: " + attributes.Alphabet
                                          + ", LanguageCode: " + attributes.LanguageCode
                                          + ", LastModified: " + attributes.LastModified
                                          + ", LexemesCount: " + attributes.LexemesCount
                                          + ", LexiconArn: " + attributes.LexiconArn
                                          + ", Size: " + attributes.Size);
                    }
                } while (nextToken != null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught: " + e.Message);
            }
        }
Beispiel #12
0
        static async Task Main()
        {
            // クライアントを作成
            var region = RegionEndpoint.APNortheast1;
            var client = new AmazonPollyClient(region);

            // Amazon Polly を呼び出してテキストを音声に変換する
            var request = new SynthesizeSpeechRequest
            {
                VoiceId      = VoiceId.Mizuki,
                LanguageCode = LanguageCode.JaJP,
                OutputFormat = OutputFormat.Mp3,
                Text         = "こんにちは"
            };
            var resp = await client.SynthesizeSpeechAsync(request);

            // 取得した音声データをファイルに保存する
            const string fileName = "result.mp3";

            using (var stream = new MemoryStream())
            {
                await resp.AudioStream.CopyToAsync(stream);

                await File.WriteAllBytesAsync(fileName, stream.ToArray());
            }
        }
Beispiel #13
0
        public static async Task Main()
        {
            var client  = new AmazonPollyClient();
            var request = new ListLexiconsRequest();

            try
            {
                Console.WriteLine("All voices: ");

                do
                {
                    var response = await client.ListLexiconsAsync(request);

                    request.NextToken = response.NextToken;

                    response.Lexicons.ForEach(lexicon =>
                    {
                        var attributes = lexicon.Attributes;
                        Console.WriteLine($"Name: {lexicon.Name}");
                        Console.WriteLine($"\tAlphabet: {attributes.Alphabet}");
                        Console.WriteLine($"\tLanguageCode: {attributes.LanguageCode}");
                        Console.WriteLine($"\tLastModified: {attributes.LastModified}");
                        Console.WriteLine($"\tLexemesCount: {attributes.LexemesCount}");
                        Console.WriteLine($"\tLexiconArn: {attributes.LexiconArn}");
                        Console.WriteLine($"\tSize: {attributes.Size}");
                    });
                }while (request.NextToken is not null);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Beispiel #14
0
        private void btn_speak_Click(object sender, EventArgs e)
        {
            var client  = new AmazonPollyClient();
            var request = new SynthesizeSpeechRequest
            {
                Text         = txt_Text.Text,
                OutputFormat = OutputFormat.Mp3,
                VoiceId      = VoiceId.Joey
            };
            var response = client.SynthesizeSpeech(request);

            var folder   = AppDomain.CurrentDomain.BaseDirectory;
            var filename = $"{folder}{Guid.NewGuid()}.mp3";

            using (var fileStream = File.Create(filename))
            {
                response.AudioStream.CopyTo(fileStream);
                fileStream.Flush();
                fileStream.Close();
            }



            IWavePlayer     waveOutDevice   = new WaveOut();
            AudioFileReader audioFileReader = new AudioFileReader(filename);

            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();
        }
Beispiel #15
0
        private void ConvertButton_Click(object sender, RoutedEventArgs e)
        {
            var client  = new AmazonPollyClient();
            var request = new SynthesizeSpeechRequest
            {
                Text         = MyTextBox.Text,
                OutputFormat = OutputFormat.Mp3,
                VoiceId      = VoiceId.Mia
            };

            var response = client.SynthesizeSpeech(request);

            var folder   = AppDomain.CurrentDomain.BaseDirectory;
            var filename = $"{folder}{Guid.NewGuid()}.mp3";

            using (var fs = File.Create(filename))
            {
                response.AudioStream.CopyTo(fs);
                fs.Flush();
                fs.Close();
            }

            var player = new MediaPlayer();

            player.Open(new Uri(filename, UriKind.Absolute));
            player.MediaEnded += (s2, e2) => Title = "Player ended";
            player.Play();
            Title = "Playing audio...";
        }
Beispiel #16
0
 //--- Methods ---
 public override Task InitializeAsync(LambdaConfig config)
 {
     Polly  = new AmazonPollyClient();
     S3     = new AmazonS3Client();
     Bucket = config.ReadS3BucketName("ArticlesBucket");
     return(Task.CompletedTask);
 }
Beispiel #17
0
        public static void start(IModHelper h)
        {
            Helper      = h;
            currentText = "";
            tmppath     = Path.Combine(Helper.DirectoryPath, "TTS");

            if (!Directory.Exists(tmppath))
            {
                Directory.CreateDirectory(tmppath);
            }

            if (pc == null)
            {
                pc = AWSHandler.getPollyClient();
            }

            currentVoice = VoiceId.Salli;
            lastText     = "";
            lastDialog   = "";
            lastHud      = "";
            speak        = false;
            runSpeech    = true;

            setVoice("default");

            speechThread = new Thread(t2sOut);
            speechThread.Start();
            h.Events.GameLoop.UpdateTicked += OnUpdateTicked;
            h.Events.Display.MenuChanged   += OnMenuChanged;
        }
        public static async Task Main(string[] args)
        {
            string lexiconName = "SampleLexicon";

            var client = new AmazonPollyClient();

            await GetPollyLexiconAsync(client, lexiconName);
        }
Beispiel #19
0
 public PollyHelper(IConfiguration configuration)
 {
     //폴리 클라이언트 생성
     _pollyClient = new AmazonPollyClient(
         configuration.GetSection("awsAccessKeyId").Value,
         configuration.GetSection("awsSecretAccessKey").Value,
         RegionEndpoint.APNortheast2);
 }
Beispiel #20
0
        public async Task <IActionResult> Login(IFormFile file)
        {
            CelebrityModel celeb = new CelebrityModel();

            Directory.Delete(_appEnvironment.WebRootPath + "/resources/", true);
            Directory.CreateDirectory(_appEnvironment.WebRootPath + "/resources/");

            if (null != file && file.Length > 0)
            {
                string speechFileName = "notjeff.mp3";
                string speechText     = "Nice try. You're not Jeff, I can't let you in.";

                AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();

                RecognizeCelebritiesRequest    recognizeCelebritiesRequest = new RecognizeCelebritiesRequest();
                Amazon.Rekognition.Model.Image img = new Amazon.Rekognition.Model.Image();

                MemoryStream memStream = new MemoryStream();
                file.CopyTo(memStream);
                img.Bytes = memStream;
                recognizeCelebritiesRequest.Image = img;

                RecognizeCelebritiesResponse recognizeCelebritiesResponse = await rekognitionClient.RecognizeCelebritiesAsync(recognizeCelebritiesRequest);

                if (null != recognizeCelebritiesResponse && recognizeCelebritiesResponse.CelebrityFaces.Count > 0)
                {
                    celeb.CelebrityName = recognizeCelebritiesResponse.CelebrityFaces[0].Name;
                    celeb.Confidence    = recognizeCelebritiesResponse.CelebrityFaces[0].MatchConfidence;

                    if (celeb.CelebrityName == "Jeff Bezos")
                    {
                        speechText     = "Hello Boss, Welcome to the Deployment Bot. Please continue to start the deployment.";
                        celeb.IsJeff   = true;
                        speechFileName = "jeff.mp3";
                    }
                }
                else
                {
                    celeb.CelebrityName = "Sure, you're popular among your friends. But that doesn't make you a celebrity.";
                    celeb.Confidence    = 0;
                }

                AmazonPollyClient pollyclient = new AmazonPollyClient();
                Amazon.Polly.Model.SynthesizeSpeechResponse speechResponse =
                    await pollyclient.SynthesizeSpeechAsync(new Amazon.Polly.Model.SynthesizeSpeechRequest()
                {
                    OutputFormat = OutputFormat.Mp3, Text = speechText, VoiceId = VoiceId.Joanna
                });

                var stream = new FileStream(_appEnvironment.WebRootPath + "/resources/" + speechFileName, FileMode.Create);
                await speechResponse.AudioStream.CopyToAsync(stream);

                stream.Close();
            }

            return(View("Login", celeb));
        }
Beispiel #21
0
 //--- Methods ---
 public override Task InitializeAsync(LambdaConfig config)
 {
     Polly             = new AmazonPollyClient();
     S3                = new AmazonS3Client();
     SnsClient         = new AmazonSimpleNotificationServiceClient();
     Bucket            = config.ReadS3BucketName("ArticlesBucket");
     NotificationTopic = config.ReadText("ArticleAudioDone");
     return(Task.CompletedTask);
 }
 //--Methods--
 public override Task InitializeAsync(LambdaConfig config)
 {
     _rand             = new Random();
     _textBucket       = new S3Bucket(config.ReadText("TextForPolly"));
     _audioBucket      = new S3Bucket(config.ReadText("AudioForTranscribe"));
     _pollyClient      = new AmazonPollyClient();
     _transcribeClient = new AmazonTranscribeServiceClient();
     return(Task.CompletedTask);
 }
Beispiel #23
0
 public void HappyCaseAPI()
 {
     using (var client = new AmazonPollyClient(RegionEndpoint.USWest2))
     {
         var response = client.SynthesizeSpeech(GetMp3Request());
         Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
         Assert.IsTrue(response.AudioStream.ReadByte() > -1);
     }
 }
        static AWSPolly()   //TODO move credentials into external file
        {
            Amazon.Runtime.AWSCredential cred = new Amazon.Runtime.AWSCredential(
                "ASIA2RT5FL2BKHNXWLWQ",
                "ta0uE8DZk6FmcniacHdOGoObgoYx9cq17LCMxHR/",
                "FQoGZXIvYXdzEEcaDKuVyK/fzl2XG2u3NyKBAnmVS++LMNOcnCTfWpIQ2fmTGb5/mUK+8qSOb/eRhV4ENEPIVYnFTD7x0Ghsk9j0bdLDMLBaTrbyFrlhHGCPQ9vmJZM2p4BHf/ihn8u/587FnaNbRUIDSjhb+GlnV6noR9665RnD2LHp95Comv5+LzdosyQUxi071BHat4OqqOwt13nN2a4+X7HRtBJpv5D0XA47GBmBkY1oOZ1mKIpv/r7gaU5ReONGygJfg2QH3jqDULGeQ4KzXa5qIcgED1XuU6O9q2lwEFzbUjl/5PRRbpnj7Z0xe96keLLeuYMRDbgGCuj8dCYt+71ammVCBJ3gfYYbsGNkFX5GyIt6+naSYPX6KPz4id8F");

            pc = new AmazonPollyClient(cred, Amazon.RegionEndpoint.USEast1);
        }
        public static async Task Main()
        {
            string outputFileName = "speech.mp3";
            string text           = "Twas brillig, and the slithy toves did gyre and gimbol in the wabe";

            var client   = new AmazonPollyClient();
            var response = await PollySynthesizeSpeech(client, text);

            WriteSpeechToStream(response.AudioStream, outputFileName);
        }
Beispiel #26
0
        public static async Task Main(string[] args)
        {
            var client = new AmazonS3Client(RegionEndpoint.EUWest2);
            ListBucketsResponse buckets_response = await client.ListBucketsAsync();

            foreach (var bucket in buckets_response.Buckets)
            {
                ListObjectsV2Request req = new ListObjectsV2Request();
                req.BucketName = bucket.BucketName;
                // NOTE if this finds a folder it includes the folder as an object, and its content as
                // more objects.  I thought folders didn't exist as such, but it seems they do.
                ListObjectsV2Response res = await client.ListObjectsV2Async(req);

                int len = res.S3Objects.Count;
                Console.WriteLine(bucket.BucketName + " date:" + bucket.CreationDate + " has " + len + " objects.");
                if (len > 0)
                {
                    foreach (var obj in res.S3Objects)
                    {
                        Console.WriteLine("   " + obj.Key + " " + obj.Size + " " + obj.StorageClass + " " + obj.ETag);
                    }
                }
            }

            var pollyclient = new AmazonPollyClient();
            SynthesizeSpeechRequest request = new SynthesizeSpeechRequest();

            request.Text         = "Hello my lovely little world.";
            request.OutputFormat = OutputFormat.Mp3;
            request.VoiceId      = VoiceId.Emma;
            var pollyres = await pollyclient.SynthesizeSpeechAsync(request);

            var fs    = new FileStream("c:/tmp/hw.mp3", FileMode.Create);
            var instr = pollyres.AudioStream;

            byte[] bytes = new byte[256];
            int    count = 0;

            while (true) //count < instr.Length)
            {
                int c = instr.Read(bytes, 0, 256);
                if (c == 0)
                {
                    break;
                }
                fs.Write(bytes, 0, c);
                count += c;
            }
            fs.Close();
            var okater = new NetCoreAudio.Player();

            okater.Play("c:/tmp/hw.mp3").Wait();
            Console.WriteLine("Thanks for all the fish");
            Console.ReadLine();
        }
Beispiel #27
0
        private void Speak(string message, VoiceId voiceId, AmazonPollyClient pollyClient)
        {
            var audioConfiguration = configurationManager.LoadConfiguration <AudioConfiguration>();

            audioConfiguration.InitializeConfiguration();

            const int volume = 100;

            if (pollyClient == null)
            {
                pollyClient = GetPollyClient();
            }

            if (voiceId == null)
            {
                voiceId = pollyClient.DescribeVoices(new Amazon.Polly.Model.DescribeVoicesRequest {
                    LanguageCode = "de-DE"
                }).Voices.FirstOrDefault()?.Id;

                if (voiceId == null)
                {
                    return;
                }
            }

            string ttsPath = Path.Combine(soundPathProvider.Path, "tts");

            if (!Directory.Exists(ttsPath))
            {
                Directory.CreateDirectory(ttsPath);
            }

            var synthesizeResponse = pollyClient.SynthesizeSpeech(new Amazon.Polly.Model.SynthesizeSpeechRequest()
            {
                OutputFormat = OutputFormat.Mp3, Text = message, VoiceId = voiceId
            });
            string ttsFilePath = Path.Combine(ttsPath, "tts.mp3");

            using var fileStream = new FileStream(ttsFilePath, FileMode.Create);
            synthesizeResponse.AudioStream.CopyTo(fileStream);

            synthesizeResponse.AudioStream.Close();
            synthesizeResponse.AudioStream.Dispose();

            using var reader       = new MediaFoundationReader(ttsFilePath);
            using var volumeStream = new WaveChannel32(reader);
            using var outputStream = new WasapiOut(audioConfiguration.SelectedSoundCommandDevice, NAudio.CoreAudioApi.AudioClientShareMode.Shared, false, 10);
            volumeStream.Volume    = NormalizeVolume(volume);
            outputStream.Init(volumeStream);
            outputStream.Play();

            Thread.Sleep(reader.TotalTime.Add(TimeSpan.FromMilliseconds(100)));

            outputStream.Stop();
        }
Beispiel #28
0
        void InitializePolly(string awsID, string awsSecret, string region)
        {
            RegionEndpoint _region = RegionEndpoint.GetBySystemName(region);

            _pc = new AmazonPollyClient(awsID, awsSecret, _region);

            if (_pc != null)
            {
                initialized = true;
            }
        }
Beispiel #29
0
 //--Methods--
 public override Task InitializeAsync(LambdaConfig config)
 {
     _audioBucket      = AwsConverters.ConvertBucketArnToName(config.ReadText("AudioForTranscribe"));
     _textBucket       = AwsConverters.ConvertBucketArnToName(config.ReadText("TextForPolly"));
     _topic            = config.ReadText("Loop");
     _rand             = new Random();
     _s3Client         = new AmazonS3Client();
     _pollyClient      = new AmazonPollyClient();
     _transcribeClient = new AmazonTranscribeServiceClient();
     _snsClient        = new AmazonSimpleNotificationServiceClient();
     return(Task.CompletedTask);
 }
Beispiel #30
0
 public void APIWithSpeechMarks()
 {
     using (var client = new AmazonPollyClient(RegionEndpoint.USWest2))
     {
         var response = client.SynthesizeSpeech(GetSpeechMarkRequest());
         Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
         using (var streamReader = new StreamReader(response.AudioStream))
         {
             AssertSpeechMarks(JsonMapper.ToObject(streamReader));
         }
     }
 }