예제 #1
0
        private static HttpRequestMessage GetRequest(Ssml ssml)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, EndPointUrl + ApiKey);

            request.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(ssml.ToString()));
            request.Content.Headers.ContentType = new MediaTypeHeaderValue(ContentType);
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(Accept));
            return(request);
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Ssml ssml = new Ssml();

            ssml.StartVoice("nozomi");
            ssml.AppendText(textBox1.Text);
            ssml.EndVoice();
            byte[] result   = TextToSpeechClient.SendRequest(ssml);
            string fileName = GetSaveFileName();
        }
예제 #3
0
 public static byte[] SendRequest(Ssml ssml)
 {
     using (HttpClient client = new HttpClient())
     {
         try
         {
             var responseMessage = client.SendAsync(GetRequest(ssml));
             responseMessage.Wait();
             if (responseMessage.Result.StatusCode == System.Net.HttpStatusCode.OK)
             {
                 var content = responseMessage.Result.Content;
                 var stream  = content.ReadAsStreamAsync().GetAwaiter().GetResult();
                 using (MemoryStream ms = new MemoryStream())
                 {
                     byte[] buf = new byte[1024 * 1024]; // 1m
                     while (true)
                     {
                         int read = stream.Read(buf, 0, buf.Length);
                         if (read <= 0)
                         {
                             break;
                         }
                         ms.Write(buf, 0, buf.Length);
                     }
                 }
             }
         }
         catch (Exception)
         {
             throw;
         }
         finally
         {
         }
     }
     return(null);
 }