SpeechSynthesizer.SetOutputToWaveFile Método
Definição
Configura o objeto SpeechSynthesizer para acrescentar a saída a um arquivo de formato de áudio de forma de onda.Configures the SpeechSynthesizer object to append output to a Waveform audio format file.
Sobrecargas
| SetOutputToWaveFile(String, SpeechAudioFormatInfo) |
Configura o objeto SpeechSynthesizer para acrescentar a saída a um arquivo de formato de áudio de forma de onda em um formato especificado.Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format. |
| SetOutputToWaveFile(String) |
Configura o objeto SpeechSynthesizer para acrescentar a saída a um arquivo que contém o áudio do formato Waveform.Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio. |
Comentários
Para liberar a SpeechSynthesizer referência do arquivo, reconfigure a SpeechSynthesizer saída do, por exemplo, chamando SetOutputToNull .To release the SpeechSynthesizer's reference to the file, reconfigure the SpeechSynthesizer's output, for example, by calling SetOutputToNull.
Para obter outras opções de configuração de saída, consulte os SetOutputToAudioStream métodos,, SetOutputToDefaultAudioDevice SetOutputToNull e SetOutputToWaveStream .For other output configuration options, see the SetOutputToAudioStream, SetOutputToDefaultAudioDevice, SetOutputToNull, and SetOutputToWaveStream methods.
SetOutputToWaveFile(String, SpeechAudioFormatInfo)
Configura o objeto SpeechSynthesizer para acrescentar a saída a um arquivo de formato de áudio de forma de onda em um formato especificado.Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format.
public:
void SetOutputToWaveFile(System::String ^ path, System::Speech::AudioFormat::SpeechAudioFormatInfo ^ formatInfo);
public void SetOutputToWaveFile (string path, System.Speech.AudioFormat.SpeechAudioFormatInfo formatInfo);
member this.SetOutputToWaveFile : string * System.Speech.AudioFormat.SpeechAudioFormatInfo -> unit
Public Sub SetOutputToWaveFile (path As String, formatInfo As SpeechAudioFormatInfo)
Parâmetros
- path
- String
O caminho para o arquivo.The path to the file.
- formatInfo
- SpeechAudioFormatInfo
As informações de formato de áudio.The audio format information.
Exemplos
O exemplo a seguir especifica o formato da saída da síntese de fala e a envia para um arquivo WAV.The following example specifies the format of the output of speech synthesis and sends it to a WAV file.
using System;
using System.IO;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;
namespace SampleSynthesis
{
class Program
{
static void Main(string[] args)
{
// Initialize a new instance of the SpeechSynthesizer.
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Configure the audio output.
synth.SetOutputToWaveFile(@"C:\temp\test.wav",
new SpeechAudioFormatInfo(32000, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
// Create a SoundPlayer instance to play output audio file.
System.Media.SoundPlayer m_SoundPlayer =
new System.Media.SoundPlayer(@"C:\temp\test.wav");
// Build a prompt.
PromptBuilder builder = new PromptBuilder();
builder.AppendText("This is sample output to a WAVE file.");
// Speak the prompt.
synth.Speak(builder);
m_SoundPlayer.Play();
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
Confira também
- SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)
- SetOutputToDefaultAudioDevice()
- SetOutputToNull()
- SetOutputToWaveStream(Stream)
Aplica-se a
SetOutputToWaveFile(String)
Configura o objeto SpeechSynthesizer para acrescentar a saída a um arquivo que contém o áudio do formato Waveform.Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio.
public:
void SetOutputToWaveFile(System::String ^ path);
public void SetOutputToWaveFile (string path);
member this.SetOutputToWaveFile : string -> unit
Public Sub SetOutputToWaveFile (path As String)
Parâmetros
- path
- String
O caminho para o arquivo.The path to the file.
Exemplos
O exemplo a seguir usa uma instância do SoundPlayer para reproduzir um prompt que tem saída para um arquivo. wav.The following example uses an instance of SoundPlayer to play a prompt that has been output to a .wav file. Como a SpeakAsync chamada é assíncrona, a SoundPlayer instância é criada (e o Play método invocado) no manipulador para o SpeakCompleted evento.Because the SpeakAsync call is asynchronous, the SoundPlayer instance is created (and the Play method invoked) in the handler for the SpeakCompleted event.
using System;
using System.Speech.Synthesis;
namespace SampleSynthesis
{
class Program
{
static void Main(string[] args)
{
// Initialize a new instance of the SpeechSynthesizer.
SpeechSynthesizer synth = new SpeechSynthesizer();
// Configure the audio output.
synth.SetOutputToWaveFile(@"C:\Test\Sample.wav");
// Register for the SpeakCompleted event.
synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);
// Build a prompt.
PromptBuilder builder = new PromptBuilder();
builder.AppendText("This sample asynchronously speaks a prompt to a WAVE file.");
// Speak the string asynchronously.
synth.SpeakAsync(builder);
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
// Handle the SpeakCompleted event.
static void synth_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
// Create a SoundPlayer instance to play the output audio file.
System.Media.SoundPlayer m_SoundPlayer =
new System.Media.SoundPlayer(@"C:\Test\Sample.wav");
// Play the output file.
m_SoundPlayer.Play();
}
}
}
Comentários
Para configurar a saída e especificar o formato de áudio, use o SetOutputToWaveFile método.To configure the output and specify the audio format, use the SetOutputToWaveFile method.
Confira também
- SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)
- SetOutputToDefaultAudioDevice()
- SetOutputToNull()
- SetOutputToWaveStream(Stream)