2017-01-13 6 views
0

Amazon Web Services PollyおよびAWS SDK for C#を使用してテキストを音声変換しようとしています。Amazon Pollyテキストから音声への変換時にゼロバイトオーディオストリームを受信

Empty audio stream 1 Empty audio stream 2

何が欠けています:私は、オーディオストリームが空であるしかしHTTP 200 OK応答(例外がスローされません)を受信

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); 

:私は非常に基本的な変換をしようとしましたか?

答えて

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(); 
     } 
    } 
} 
0

私はあなたが保存(あるいは長さを参照)の前にあなたがしなければならないすべては、ストリームのフラッシュであると考えています

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

これがあなたにとって魅力的なものかどうかを確認してください。

関連する問題