Skip to content

Instantly share code, notes, and snippets.

@shiyuugohirao
Created November 6, 2018 04:24
Show Gist options
  • Save shiyuugohirao/da2d2306a021f415d71694d290a86104 to your computer and use it in GitHub Desktop.
Save shiyuugohirao/da2d2306a021f415d71694d290a86104 to your computer and use it in GitHub Desktop.
ofSoundPlayer with std::thread
void play(string soundPath, bool bOneShotLife=false){
if(ofFile::doesFileExist(soundPath)){
thread soundThread([=]{
ofSoundPlayer sp;
sp.load(soundPath);
sp.setLoop(false);
cout<< "play talk";
int t = ofGetElapsedTimeMicros();
sp.play();
while(sp.isLoaded() && sp.isPlaying()){}
cout << " - about"<< ((ofGetElapsedTimeMicros() - t)*0.000001) <<"sec"<<endl;
if(bOneShotLife && ofFile::doesFileExist(soundPath)) ofFile::removeFile(soundPath);
//else ofLogError("ofxOpenJTalk")<<"not found audio file ("<<soundPath<<")";
});
soundThread.detach();
}else{
ofLogError("ofxOpenJTalk")<<"not found audio file ("<<soundPath<<")";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment