我一直在尝试制作一个关于如何使用 polly 的 hello wold 示例(https://aws.amazon.com/polly/)
我不想下载任何库。我只想用我的凭据向亚马逊网络服务发出一个简单的 http 请求并取回音频。那可能吗?
我已经在 IAM 上创建了一个用户,它看起来像这样:
这是我到目前为止所拥有的,它不会将文本转换为语音。我认为问题在于身份验证。:/
static void Main(string[] args)
{
var accessKeyId = @"I place in here my access key";
var secretKey = @"I place in here my secret key";
//Amazon.Runtime.AWSCredentials credentials = new
AmazonPollyClient client = new AmazonPollyClient(accessKeyId, secretKey);
// Create describe voices request.
DescribeVoicesRequest describeVoicesRequest = new DescribeVoicesRequest();
// Synchronously ask Amazon Polly to describe available TTS voices.
DescribeVoicesResponse describeVoicesResult = client.DescribeVoices(describeVoicesRequest);
List<Voice> voices = describeVoicesResult.Voices;
// Create speech synthesis request.
SynthesizeSpeechRequest synthesizeSpeechPresignRequest = new SynthesizeSpeechRequest();
// Text
synthesizeSpeechPresignRequest.Text = "Hello world!";
// Select voice for synthesis.
synthesizeSpeechPresignRequest.VoiceId = voices[0].Id;
// Set format to MP3.
synthesizeSpeechPresignRequest.OutputFormat = OutputFormat.Mp3;
// Get the presigned URL for synthesized speech audio stream.
var presignedSynthesizeSpeechUrl = client.SynthesizeSpeechAsync(synthesizeSpeechPresignRequest).GetAwaiter().GetResult();
using (FileStream output = File.OpenWrite("hello_world.mp3"))
{
presignedSynthesizeSpeechUrl.AudioStream.CopyTo(output);
}
Console.Read();
}
请注意,要编译此示例,我必须添加 nuget 包AWSSDK.Polly