David
David

Reputation: 23

SAPI Audio balance/pan options

I'm exploring options for two independent, concurrently running Win32 applications on a Windows 7 Embedded platform to output their audio to respective channels of the audio output device (i.e. Application 'A' uses left channel, and application 'B' uses the right).

In this instance, Application A is a pre-existing C++ app which uses the SAPI TTS engine. (Application B is a yet-to-be-written app).

Whilst the SAPI interface provides a volume property, there doesn't appear to be the provision to nominate a pan/balance setting.

I've given Virtual Audio Cable a try, thinking that might enable connection to either the left or right channel, but it doesn't.

Any suggestions, programmatic or otherwise?

Upvotes: 1

Views: 262

Answers (1)

user1575095
user1575095

Reputation:

SAPI doesn't really do much audio processing for speech synthesis outside of volume, pitch, and rate. Even with that said, I've encountered SAPI voices that do not even implement those three things.

You will probably want to output your synthesized speech as a .wav file, and manipulate that output with another library to do panning.

Here's some code that will show you how to output to a .wav file using SAPI in C++.

#include <sapi.h>
#include <sphelper.h>
#include <iostream>

int main(int argc, char* argv[])
{

    HRESULT hr = S_OK;
    CComPtr<ISpObjectToken> cpVoiceToken;
    CComPtr<ISpVoice> cpVoice;
    CSpStreamFormat cAudioFmt;
    CComPtr<ISpStream> cpStream;

    ::CoInitialize(NULL);

    if(SUCCEEDED(hr))
        hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
    if(SUCCEEDED(hr))
        hr = SPBindToFile(L"E:\\fileName.wav", SPFM_CREATE_ALWAYS, &cpStream, &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
    if(SUCCEEDED(hr))
        hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
    if(SUCCEEDED(hr))
        cpVoice->SetOutput(cpStream, TRUE);
    if(SUCCEEDED(hr))
        hr = cpVoice->Speak(L"My spoken text goes here", SPF_DEFAULT, NULL);

    cpStream->Close();
    cpStream.Release();
    cpVoice.Release();
    ::CoUninitialize();

    std::printf("%s", "Press any key to continue...");
    std::getchar();
}

Upvotes: 1

Related Questions