示例#1
0
 private static void Form_GenerateSpeech(object sender, GenerateSpeechEventArgs e)
 {
     _ = Task.Run(async() =>
     {
         try
         {
             if (e.FileName is not null)
             {
                 var newStream = await client.GetAudioDataStreamAsync(e.Format, e.Text, e.Voice, e.RateChange, e.PitchChange)
                                 .ConfigureAwait(true);
                 SaveStream(newStream, e.FileName);
             }
             else if (!e.DecodeRequired)
             {
                 var newStream = await client.GetAudioDataStreamAsync(e.Format, e.Text, e.Voice, e.RateChange, e.PitchChange)
                                 .ConfigureAwait(true);
                 PlayStream(newStream);
             }
             else
             {
                 var newStream = await client.GetWaveAudioAsync(e.Format, e.Text, e.Voice, e.RateChange, e.PitchChange)
                                 .ConfigureAwait(true);
                 PlayStream(newStream);
             }
         }
         catch (Exception exp)
         {
             form.SetError(exp);
         }
     });
 }
示例#2
0
 private static void Form_GenerateSpeech(object sender, GenerateSpeechEventArgs e)
 {
     _ = Task.Run(async() =>
     {
         try
         {
             client.OutputFormat = e.Format;
             var newStream       = await client.GetAudioDataStreamAsync(e.Text, e.Voice, e.RateChange, e.PitchChange)
                                   .ConfigureAwait(true);
             if (e.FileName is object)
             {
                 SaveStream(newStream, e.FileName);
             }
             else
             {
                 PlayStream(newStream);
             }
         }
         catch (Exception exp)
         {
             form.SetError(exp);
         }
     });
 }