Share via


TtsEngineSsml.GetOutputFormat(SpeakOutputFormat, IntPtr) 方法

定義

傳回指定的合成引擎所支援的最符合音訊輸出,以回應合成器引擎支援特定輸出格式的要求。

public:
 abstract IntPtr GetOutputFormat(System::Speech::Synthesis::TtsEngine::SpeakOutputFormat speakOutputFormat, IntPtr targetWaveFormat);
public abstract IntPtr GetOutputFormat (System.Speech.Synthesis.TtsEngine.SpeakOutputFormat speakOutputFormat, IntPtr targetWaveFormat);
abstract member GetOutputFormat : System.Speech.Synthesis.TtsEngine.SpeakOutputFormat * nativeint -> nativeint
Public MustOverride Function GetOutputFormat (speakOutputFormat As SpeakOutputFormat, targetWaveFormat As IntPtr) As IntPtr

參數

speakOutputFormat
SpeakOutputFormat

SpeakOutputFormat 列舉的有效成員,表示要求的音訊輸出格式的型別。

targetWaveFormat
IntPtr

nativeint

struct(其包含speakOutputFormat引數所要求的音訊格式類型的詳細設定)的指標。

傳回

IntPtr

nativeint

傳回有效的 IntPtr 執行個體,參考包含輸出格式詳細資訊的 struct

範例

下列範例實作會驗證選取的輸入,如果輸入位於容錯範圍內,請使用它們,否則使用預設值。

public IntPtr GetOutputFormat(SpeakOutputFormat format, IntPtr targetWaveFormat) {  
    WaveFormat waveFormat = new WaveFormat();  
    WaveFormat rq=new WaveFormat();  
    Marshal.PtrToStructure(targetWaveFormat,rq);  

    waveFormat.AvgBytesPerSec = AvgBytesPerSec Min < rq.AvgBytesPerSec && rq.AvgBytesPerSec < AvgBytesPerSecMax? rq.AvgBytesPerSec : 3200;  
    waveFormat.BitsPerSample = BitsPerSampleMin < rq.AvgBytesPerSec && rq.BitsPerSample < BitsPerSampleMax ? rq.AvgBytesPerSec : 3200; 16;  
    waveFormat.BlockAlign = 2;  
    waveFormat.Channels = 1;  
    waveFormat.FormatTag = 1;  
    waveFormat.SamplesPerSec = 16000;  
    waveFormat.Size = 0;  

    IntPtr wfx = Marshal.AllocCoTaskMem(Marshal.SizeOf(waveFormat));  
    Marshal.StructureToPtr(waveFormat, wfx, false);  

    //Console.WriteLine ("GetOutputFormat called");  
    return wfx;  
}  
internal struct WaveFormat {  
    public Int16 FormatTag;  
    public Int16 Channels;  
    public int SamplesPerSec;  
    public int AvgBytesPerSec;  
    public Int16 BlockAlign;  
    public Int16 BitsPerSample;  
    public Int16 Size;  
}  

備註

方法所使用的 targetWaveFormat 結構應該與 SAPI 下可用的 相容 WAVEFORMATEX ,而且應該使用 配置 CoTaskMemAlloc 傳回的值。

struct必須提供相當於:

internal struct WaveFormat  
{  
    public Int16 FormatTag;  
    public Int16 Channels;  
    public int SamplesPerSec;  
    public int AvgBytesPerSec;  
    public Int16 BlockAlign;  
    public Int16 BitsPerSample;  
    public Int16 Size;  
}  

給實施者的注意事項

繼承自 TtsEngineSsml 的物件應該檢查所指定的 targetWaveFormat 輸出格式,並傳回它支援的最接近格式。

適用於