語言

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 結構與回傳的結構應與 WAVEFORMATEX SAP 所提供的相容,回傳值應以 為基礎 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 檢查所請求的輸出格式,並回傳最接近的格式。

適用於