TtsEngineSsml.GetOutputFormat Method (SpeakOutputFormat, IntPtr)

 

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.

Namespace:   System.Speech.Synthesis.TtsEngine
Assembly:  System.Speech (in System.Speech.dll)

public abstract IntPtr GetOutputFormat(
	SpeakOutputFormat speakOutputFormat,
	IntPtr targetWaveFormat
)

Parameters

speakOutputFormat
Type: System.Speech.Synthesis.TtsEngine.SpeakOutputFormat

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

targetWaveFormat
Type: System.IntPtr

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

Return Value

Type: System.IntPtr

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

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 Inheritors:

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

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

.NET Framework
Available since 3.0
Return to top
Show: