SpeechSynthesizer.SetOutputToWaveFile Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Configura o SpeechSynthesizer objeto para adicionar saída a um ficheiro de formato áudio Waveform.
Sobrecargas
| Name | Description |
|---|---|
| SetOutputToWaveFile(String, SpeechAudioFormatInfo) |
Configura o SpeechSynthesizer objeto para adicionar saída a um ficheiro de formato de áudio de forma de onda num formato especificado. |
| SetOutputToWaveFile(String) |
Configura o SpeechSynthesizer objeto para adicionar saída a um ficheiro que contenha áudio em formato de forma de onda. |
Observações
Para libertar a SpeechSynthesizerreferência de 's ao ficheiro, reconfigure a SpeechSynthesizersaída de 's, por exemplo, chamando SetOutputToNull.
Para outras opções de configuração de saída, veja os SetOutputToAudioStreammétodos , SetOutputToDefaultAudioDevice, SetOutputToNull, e SetOutputToWaveStream .
SetOutputToWaveFile(String, SpeechAudioFormatInfo)
- Origem:
- SpeechSynthesizer.cs
- Origem:
- SpeechSynthesizer.cs
- Origem:
- SpeechSynthesizer.cs
- Origem:
- SpeechSynthesizer.cs
Configura o SpeechSynthesizer objeto para adicionar saída a um ficheiro de formato de áudio de forma de onda num formato especificado.
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 ficheiro.
- formatInfo
- SpeechAudioFormatInfo
A informação do formato áudio.
Exemplos
O exemplo seguinte especifica o formato da saída da síntese de voz e envia-a para um ficheiro WAV.
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();
}
}
}
Ver também
- SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)
- SetOutputToDefaultAudioDevice()
- SetOutputToNull()
- SetOutputToWaveStream(Stream)
Aplica-se a
SetOutputToWaveFile(String)
- Origem:
- SpeechSynthesizer.cs
- Origem:
- SpeechSynthesizer.cs
- Origem:
- SpeechSynthesizer.cs
- Origem:
- SpeechSynthesizer.cs
Configura o SpeechSynthesizer objeto para adicionar saída a um ficheiro que contenha áudio em formato de forma de onda.
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 ficheiro.
Exemplos
O exemplo seguinte utiliza uma instância de SoundPlayer para reproduzir um prompt que foi enviado para um ficheiro .wav. Como a SpeakAsync chamada é assíncrona, a SoundPlayer instância é criada (e o Play método invocado) no handler do SpeakCompleted evento.
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();
}
}
}
Observações
Para configurar a saída e especificar o formato de áudio, use o SetOutputToWaveFile método.
Ver também
- SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)
- SetOutputToDefaultAudioDevice()
- SetOutputToNull()
- SetOutputToWaveStream(Stream)