Compartilhar via


TtsEngineSsml.GetOutputFormat(SpeakOutputFormat, IntPtr) Method

Definition

Returns the best matching audio output supported by a given synthesize engine response to a request to the synthesizer engine for the support of a particular output format.

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

Parameters

speakOutputFormat
SpeakOutputFormat

Valid member of the SpeakOutputFormat enumeration indicating the type of requested audio output format.

targetWaveFormat
IntPtr

nativeint

A pointer to a struct containing detail setting for the audio format type requested by the speakOutputFormat argument.

Returns

IntPtr

nativeint

Returns a valid IntPtr instance referring to a struct containing detailed information about the output format.

Examples

The sample implementation below validates selected inputs, using them if they are within tolerances, otherwise using default values.

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;  
}  

Remarks

The structure used as targetWaveFormat and returned by the method should compatible with the WAVEFORMATEX available under SAPI, and the returned value should be allocated using CoTaskMemAlloc.

The struct must provide functionality equivalent to:

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

Notes to Implementers

Object inheriting from TtsEngineSsml should examine the requested output format as specified by targetWaveFormat and return the closest format that it supports.

Applies to