SpeechSynthesizer.SetOutputToWaveFile Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Konfigurerar objektet SpeechSynthesizer för att lägga till utdata i en Waveform-ljudformatfil.
Överlagringar
| Name | Description |
|---|---|
| SetOutputToWaveFile(String, SpeechAudioFormatInfo) |
Konfigurerar objektet SpeechSynthesizer för att lägga till utdata till en Waveform-ljudformatfil i ett angivet format. |
| SetOutputToWaveFile(String) |
Konfigurerar objektet SpeechSynthesizer för att lägga till utdata till en fil som innehåller Ljud i Waveform-format. |
Kommentarer
Om du vill frigöra referensen SpeechSynthesizertill filen konfigurerar SpeechSynthesizerdu om utdata, till exempel genom att anropa SetOutputToNull.
Andra konfigurationsalternativ för utdata finns i SetOutputToAudioStreammetoderna , SetOutputToDefaultAudioDevice, SetOutputToNulloch SetOutputToWaveStream .
SetOutputToWaveFile(String, SpeechAudioFormatInfo)
- Källa:
- SpeechSynthesizer.cs
- Källa:
- SpeechSynthesizer.cs
- Källa:
- SpeechSynthesizer.cs
- Källa:
- SpeechSynthesizer.cs
Konfigurerar objektet SpeechSynthesizer för att lägga till utdata till en Waveform-ljudformatfil i ett angivet 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)
Parametrar
- path
- String
Sökvägen till filen.
- formatInfo
- SpeechAudioFormatInfo
Ljudformatinformationen.
Exempel
I följande exempel anges formatet för utdata från talsyntesen och skickar det till en WAV-fil.
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();
}
}
}
Se även
- SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)
- SetOutputToDefaultAudioDevice()
- SetOutputToNull()
- SetOutputToWaveStream(Stream)
Gäller för
SetOutputToWaveFile(String)
- Källa:
- SpeechSynthesizer.cs
- Källa:
- SpeechSynthesizer.cs
- Källa:
- SpeechSynthesizer.cs
- Källa:
- SpeechSynthesizer.cs
Konfigurerar objektet SpeechSynthesizer för att lägga till utdata till en fil som innehåller Ljud i Waveform-format.
public:
void SetOutputToWaveFile(System::String ^ path);
public void SetOutputToWaveFile(string path);
member this.SetOutputToWaveFile : string -> unit
Public Sub SetOutputToWaveFile (path As String)
Parametrar
- path
- String
Sökvägen till filen.
Exempel
I följande exempel används en instans av SoundPlayer för att spela upp en fråga som har matats ut till en .wav fil. Eftersom anropet SpeakAsync är asynkront skapas instansen SoundPlayerPlay (och metoden anropas) i hanteraren för SpeakCompleted händelsen.
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();
}
}
}
Kommentarer
Använd metoden för att konfigurera utdata och ange ljudformatet SetOutputToWaveFile .
Se även
- SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)
- SetOutputToDefaultAudioDevice()
- SetOutputToNull()
- SetOutputToWaveStream(Stream)