1

我正在尝试使用 Amazon Web Services Polly 和适用于 C# 的 AWS 开发工具包进行文本到语音的转换。我尝试了一个非常基本的转换:

AmazonPollyClient client = new AmazonPollyClient("secret", "secret", Amazon.RegionEndpoint.USEast1);
Amazon.Polly.Model.SynthesizeSpeechRequest request = new SynthesizeSpeechRequest();
request.OutputFormat = OutputFormat.Mp3;
request.Text = "This is my first conversion";
request.TextType = TextType.Text;
request.VoiceId = VoiceId.Nicole;
Amazon.Polly.Model.SynthesizeSpeechResponse response = client.SynthesizeSpeech(request);

我收到一个HTTP 200 OK响应(没有抛出异常)但是音频流是空的:

空音频流 1 空音频流 2

少了什么东西?

4

2 回答 2

1

返回AudioStream的没有长度,直到你在某个地方读到它,比如读到一个文件中:

using System;
using System.IO;
using Amazon;
using Amazon.Polly;
using Amazon.Polly.Model;
namespace AwsPollySO1
{
    class Program
    {
        public static void Main(string[] args)
        {
            AmazonPollyClient client = new AmazonPollyClient("yourID", "yourSecretKey", RegionEndpoint.USEast1);
            SynthesizeSpeechRequest request = new SynthesizeSpeechRequest();
            request.OutputFormat = OutputFormat.Mp3;
            request.Text = "This is my first conversion";
            request.TextType = TextType.Text;
            request.VoiceId = VoiceId.Nicole;
            SynthesizeSpeechResponse response = client.SynthesizeSpeech(request);
            Console.WriteLine("ContentType: " + response.ContentType);
            Console.WriteLine("RequestCharacters: " + response.RequestCharacters);
            FileStream destination = File.Open(@"c:\temp\myfirstconversion.mp3", FileMode.Create);
            response.AudioStream.CopyTo(destination);
            Console.WriteLine("Destination length: {0}", destination.Length.ToString());
            destination.Close();
            Console.Read();
        }
    }
}
于 2017-01-28T20:49:44.803 回答
0

我相信您所要做的就是在保存之前刷新流(甚至查看长度)

response.AudioStream.CopyTo(destination);
destination.Flush();

看看这是否对你有用。

于 2017-06-10T01:48:25.013 回答