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.

C#
public abstract IntPtr GetOutputFormat(System.Speech.Synthesis.TtsEngine.SpeakOutputFormat speakOutputFormat, IntPtr targetWaveFormat);

Parameters

speakOutputFormat
SpeakOutputFormat

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

targetWaveFormat
IntPtr

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

Returns

IntPtr

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

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)