Skip to main content
Participant
May 29, 2018

SAPI TTS playing on windows but not in oculus

Hi guys, 

I have set up an actor which on begin says a sentence just to test how this will work, I have added SAPI using VS but when I preview the app in VR, I hear the sentence come out of the laptop and not through the headphones in VR, other games etc are as expected sound only from the headset and not from the PC, any suggestions on this please, I am guessing that there must be some code to send the output to the device and not the laptop but cannot find any decent documentation anywhere about SAPI and Rift. Thanks in advance for any help, this is for an open source project.

// Fill out your copyright notice in the Description page of Project Settings.

#include "TOA.h"
#include "sapi.h"
#include <sphelper.h>

ATOA::ATOA()
{
PrimaryActorTick.bCanEverTick = true;
TOAMesh = CreateDefaultSubobject<UStaticMeshComponent>("TOAMesh");
PitchValue = 0.f;
YawValue = 0.f;
RollValue = 0.f;
}

void ATOA::BeginPlay()
{

Super::BeginPlay(); 
ISpVoice * pVoice = NULL;

HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if (SUCCEEDED(hr))
{
ISpObjectToken* cpToken(NULL);
SpFindBestToken(SPCAT_VOICES, L"gender=female", L"", &cpToken);
pVoice->SetVoice(cpToken);
cpToken->Release();
hr = pVoice->Speak(L"Hello, welcome to the Intel AI VR Retail Store", 0, NULL);
}

pVoice->Release();
pVoice = NULL;
}

    2 replies

    Participant
    May 29, 2018
    Ah I think I have just found the answer, something I had noticed is the speech actually started before the game fully loaded, it seems it is being blocked. This may be the answer, run in a different thread :) 

    "I run the SAPI code in a thread so not to block my VR app from rendering."

    https://rdmilligan.wordpress.com/2016/12/04/microsoft-speech-api-sapi-with-c/
    Participant
    September 3, 2018
    I solved the blocking issue very easily in the end :D I wrapped the SAPI code in a function and used the following one liner (Where welcome is the custom SAPI function), now there is an issue where the speech is only coming out of the laptop and not the headset, will update this post once I solve that.

    // Called when the game starts or when spawned
    void ATOA::BeginPlay()
    {
    Super::BeginPlay();
    TFuture<void> A = Async<void>(EAsyncExecution::Thread, welcome);
    }