I'm implementing a speech synthesizer using Audio Unit, based on the Core Audio examples. Everything works as expected, except that StopSpeech and StopSpeechAt appear to do nothing.
Here are the speak and stop methods:
void
Synthesizer::speak( const string &text )
{
mIsSpeaking = true;
mLastText = text;
NSString *ns_text = [NSString stringWithCString:text.c_str()
encoding:[NSString defaultCStringEncoding]];
CFStringRef cf_text = (__bridge CFStringRef)ns_text;
CheckError( SpeakCFString( mAuChannel, cf_text, NULL ), "SpeakCFString failed" );
}
void
Synthesizer::stop()
{
if ( isSpeaking() ) {
mStopRequested = true;
CheckError( StopSpeech( mAuChannel ), "StopSpeech failed" );
}
else {
mIsSpeaking = false;
}
}
I've verified that StopSpeech is called on the same thread as SpeakCFString. Oddly, when I try to step into the StopSpeech call with the debugger, it skips right over it. Really weirdly, the Speech Done callback is fired when StopSpeech is called, but the speech continues regardless.
Any idea what might be going on, or things I can do to debug? Is there some workaround I could use to disable the Audio Unit node temporarily?
This is on MacOS 10.12.5.
Related
the issue is that writing csv file that was opened already
the environment is Visual 6.0 C++ (MFC)
time variable is executing time
int time = 1 ;
BOOL blNewXls = FALSE;
_Application objApp;
_Workbook objBook;
Workbooks objBooks;
Worksheets objSheets;
_Worksheet objSheet;
Range objRange;
LPDISPATCH lpDisp;
BOOL TestView::SaveTrxGeneration1ExcelFile(CString destFileName, MYSQL_ROW row, int num_fields)
{
COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if( !objApp.CreateDispatch("Excel.Application") ){AfxMessageBox("XLS ERROR"); return FALSE;}
objApp.SetVisible(TRUE);
objApp.SetUserControl(TRUE);
lpDisp = objApp.GetWorkbooks();
objBooks.AttachDispatch(lpDisp);
lpDisp = objBooks.Open(destFileName, VOptional, VOptional, VOptional,VOptional, VOptional, VOptional, VOptional, VOptional, VOptional, VOptional, VOptional, VOptional);
lpDisp2 = lpDisp;
objBook.AttachDispatch(lpDisp);
lpDisp = objBook.GetSheets();
objSheets.AttachDispatch(lpDisp);
if(time == 2)
{
if( blNewXls )
objBook.SaveAs(COleVariant(destFileName),VOptional, VOptional, VOptional, VOptional,VOptional, FALSE, VOptional, VOptional,VOptional, VOptional);
else
objBook.Save();
objBooks.Close();
objApp.Quit();
objBooks.ReleaseDispatch(); // Release the object-IDispatch binding.
objApp.ReleaseDispatch();
objBooks = NULL; // Destroy the object references.
objApp = NULL;
time = 1;
}
else
time = 2 ;
return TRUE;
}
expected result : write 2 times
actual result : access violation when open() function executes
This is not an MFC question. Really, it is an Excel OLE automation question.
Why are you making it visible and why are you calling SetUserControl(TRUE)? Neither of those things should be necessary. For some reason, it is likely hanging onto a reference and not closing Excel because you made those calls you did which are not necessary.
After you call the first time, is there still a reference to Excel running in the background? Check task manager to verify that is it running or closed.
It seems obvious to me that it is still open. If it is open, you can't open it again.
A good news for you is that a csv file doesn't require Excel OLE, you can handle this using MFC only ... there is no need to have Excel/Office installed ... handle your csv file as text file using CStdioFile: CStdioFile
I'm struggling with Adobe Air native process communication. I'd like to pass an c++ exe shellcommands stored at processArgs when started. The c++ program uses this arguments to choose device channel and symbolrate of an CAN-Bus-Adapter. The c program itself creates an json database for an html page. While the c program is processing i'd like to get some feedback of the program and if it exits adobe air should create a link for the html page with the function onExit. The c program uses standart output of iostream lib ("cout", "cerr") to send messages to adobe air.
Adobe Air script:
var process;
function launchProcess()
{
if(air.NativeProcess.isSupported)
{
setupAndLaunch();
}
else
{
air.Introspector.Console.log("NativeProcess not supported.");
}
}
function setupAndLaunch()
{
var cpp_device = $( "#device option:selected" ).val();
var cpp_channel= $("#channel option:selected").text();
var cpp_symbolRate= $("#symbolRate option:selected").val();
air.Introspector.Console.log("CHANNEL",cpp_channel);
air.Introspector.Console.log("Device",cpp_device);
air.Introspector.Console.log("Symbol Rate",cpp_symbolRate);
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
var file = air.File.applicationDirectory.resolvePath("InteractiveDocumentation.exe");
nativeProcessStartupInfo.executable = file;
var processArgs = new air.Vector["<String>"]();
processArgs.push(cpp_device);
processArgs.push(cpp_channel);
processArgs.push(cpp_symbolRate);
nativeProcessStartupInfo.arguments = processArgs;
process = new air.NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
process.addEventListener(air.IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
process.addEventListener(air.IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
process.addEventListener(air.NativeProcessExitEvent.EXIT, onExit);
}
function onOutputData(event)
{
air.Introspector.Console.log("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
function onErrorData(event)
{
air.Introspector.Console.log("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
function onExit(event)
{
air.Introspector.Console.log("Process exited with ",event.exitCode);
$("#output").html("Start");
}
function onIOError(event)
{
air.Introspector.Console.log(event.toString());
}
$(function()
{
$("#start").click(function()
{
air.Introspector.Console.log("START");
launchProcess();
});
});
the c program is quite long, and here i post only the main part
int main( int argc, char *argv[])
{
//! get shell commands for init
// echo shell commands
for( int count = 0; count < argc; count++ )
{
cout << " argv[" << count << "] "
<< argv[count];
}
// handle data
intDevice = (int)(argv[1][0] - '0');
intChannel = (int)(argv[2][0] - '0');
intChannel -= 1;
intSymbolRate = atoi(argv[3]);
//! class function calls
useDll CanFunction;
try
{
CanFunction.initProg();
CanFunction.ecuScan();
CanFunction.openSession();
CanFunction.readECU();
CanFunction.stopProg();
return 0;
}
//! exception handling
catch(int faultNumber)
{
....
}
}
First I used only the onExit listener and everything works fine. After I used start conditions adobe air only responses if i call no class functions except the CanFunction.initProg() and the onExit function was called but skipped the jQuery command to create the link. If I add the class function calls, the c program is called and the json database created but Adobe Air doesnt received any responses. The json database is still created. This confuses me.
My c program uses some *.dll files to communicate with the bus so i could imagine that it is a windows problem. But it is still weird.
Has anybody an idea why adobe air communication doesnt work with my c program if i call my class functions or why the jQuery command is skipped?
Or is there a better solution to call a c++ exe from adobe air?
I am trying to get the display name of the running service using c++. I was trying to use the GetServiceDisplayName function but it does not seem to be working, not sure why.
TTServiceBegin( const char *svcName, PFNSERVICE pfnService, bool *svc, PFNTERMINATE pfnTerm,
int flags, int argc, char *argv[], DWORD dynamiteThreadWaitTime )
{
SC_HANDLE serviceStatusHandle;
DWORD dwSizeNeeded = 0 ;
TCHAR* szKeyName = NULL ;
serviceStatusHandle=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE ,SC_MANAGER_ALL_ACCESS);
GetServiceDisplayName(serviceStatusHandle,svcName, NULL, &dwSizeNeeded);
if(dwSizeNeeded)
{
szKeyName = new char[dwSizeNeeded+1];
ZeroMemory(szKeyName,dwSizeNeeded+1);
if(GetServiceDisplayName(serviceStatusHandle ,svcName,szKeyName,&dwSizeNeeded)!=0)
{
MessageBox(0,szKeyName,"Got the key name",0);
}
}
When i run this code, i can never see the value of szKeyName in my debugger and it goes into the if block for the message box but never displays the message box. Not sure why?
Anyway to get this to work to get the display name of the service or any other/easier way to accomplish that task?
You need to use the WTSSendMessage instead of the MessageBox to interact with the active session.
WTS_SESSION_INFO* pSessionInfo = NULL;
DWORD dwSessionsCount = 0;
if(WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &dwSessionsCount))
{
for(int i=0; i<(int)dwSessionsCount; i++)
{
WTS_SESSION_INFO &si = pSessionInfo[i];
if(si.State == WTSActive)
{
DWORD dwIdCurrentSession = si.SessionId;
std::string strTitle = "Hello";
std::string strMessage = "This is a message from the service";
DWORD dwMsgBoxRetValue = 0;
if(WTSSendMessage(
WTS_CURRENT_SERVER_HANDLE,
dwIdCurrentSession,
(char*)strTitle.c_str(),
strTitle.size(),
(char*)strMessage.c_str(),
strMessage.size(),
MB_RETRYCANCEL | MB_ICONINFORMATION | MB_TOPMOST,
60000,
&dwMsgBoxRetValue,
TRUE))
{
switch(dwMsgBoxRetValue)
{
case IDTIMEOUT:
// Deal with TimeOut...
break;
case IDCANCEL:
// Deal With Cancel....
break;
}
}
else
{
// Deal With Error
}
break;
}
}
WTSFreeMemory(pSessionInfo);
}
The message box will not be visible on Windows Vista and later due to a change that has services running in a separate session (Session 0 Isolation) that does not have access to a desktop so the message box would not be visible to you, the logged on user.
On Window XP and earlier, you need to tick the Allow service to interact with desktop checkbox under the Log On tab in the service's properties dialog for your service to make message box appear.
Instead, you could write the service name out to a file or run a user application that accepts the name of the service to query and have it query and display the service name (I just tried with the posted code and it works correctly, displaying the message box).
I'm trying to add music to my game that runs on WinRT. The music should be in an encoded format (mp3, ogg, etc.) and should be streamable and be decoded by the hardware (for performance reasons).
I've looked through the samples, and found out that MediaEngine can do something like this (I hope).
However, I'm having problems making it work. I keep getting ComExceptions everytime I try to create IMFByteStream from IRandomAccessStream via MFCreateMFByteStreamOnStreamEx().
It might be that I'm not handling tasks correctly, since they are a new paradigm for me.
Here's some code (pretty similar to the sample I mentioned before):
void MyMedia::PlayMusic ()
{
try
{
StorageFolder^ installedLocation = Windows::ApplicationModel::Package::Current->InstalledLocation;
Concurrency::task<StorageFile^> m_pickFileTask = Concurrency::task<StorageFile^>(installedLocation->GetFileAsync("music.mp3"), m_tcs.get_token());
SetURL(StringHelper::toString("music.mp3"));
auto player = this;
m_pickFileTask.then([&player](StorageFile^ fileHandle)
{
Concurrency::task<IRandomAccessStream^> fOpenStreamTask = Concurrency::task<IRandomAccessStream^> (fileHandle->OpenAsync(Windows::Storage::FileAccessMode::Read));
fOpenStreamTask.then([&player](IRandomAccessStream^ streamHandle)
{
try
{
player->SetBytestream(streamHandle);
if (player->m_spMediaEngine)
{
MEDIA::ThrowIfFailed(
player->m_spMediaEngine->Play()
);
}
} catch(Platform::Exception^)
{
MEDIA::ThrowIfFailed(E_UNEXPECTED);
}
}
);
}
);
} catch(Platform::Exception^ ex)
{
Printf("error: %s", ex->Message);
}
}
void MyMedia::SetBytestream(IRandomAccessStream^ streamHandle)
{
HRESULT hr = S_OK;
ComPtr<IMFByteStream> spMFByteStream = nullptr;
//The following line always throws a ComException
MEDIA::ThrowIfFailed(
MFCreateMFByteStreamOnStreamEx((IUnknown*)streamHandle, &spMFByteStream)
);
MEDIA::ThrowIfFailed(
m_spEngineEx->SetSourceFromByteStream(spMFByteStream.Get(), m_bstrURL)
);
return;
}
Bonus: If you know a better solution to my audio needs, please leave a comment.
I managed to fix this. There was two problems I found.
Media Foundation was not initialized
MFStartup(MF_VERSION); needs to be called before Media Foundation can be used. I added this code just before creating the media engine.
Referencing a pointer.
Line m_pickFileTask.then([&player](StorageFile^ fileHandle) should be m_pickFileTask.then([player](StorageFile^ fileHandle). This is already a pointer to the current class, and & provides the address of variable, so I was actually passing the pointer's pointer.
What XPCOM interfaces should I use to detect opening, closing and switching of tabs and also get their associated URL from a firefox extension?
I have seen instances of code that manage tabs in JS, but how about from C++ ?
You can write small JS component that will reroute tab events to your C++ component using nsIObserverService.
In C++ code you can use this snippet to register your component as observer to user defined events that is used for rerouting tab events.
NS_IMETHODIMP MyCppComponent::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if( !strcmp( aTopic, "xpcom-startup" ) )
{
nsCOMPtr<nsIObserverService> observerService =
do_GetService( "#mozilla.org/observer-service;1" );
observerService->AddObserver( this, "my-tab-open", false );
observerService->AddObserver( this, "my-tab-close", false );
observerService->AddObserver( this, "my-tab-select", false );
}
else if( !strcmp( aTopic, "my-tab-open" ) )
{
/* . . . */
}
else if( !strcmp( aTopic, "my-tab-close" ) )
{
/* . . . */
}
else if( !strcmp( aTopic, "my-tab-select" ) )
{
/* . . . */
}
/* . . . */
}
And in helper JS component you should to subscribe to tab events and in event handlers you can extract desired data and raise user defined events to execute C++ code.
function tabOpened(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.notifyObservers(event.target.linkedBrowser.contentWindow,
"my-tab-open", "some data");
}
function tabClosed(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.notifyObservers(event.target.linkedBrowser.contentWindow,
"my-tab-close", "some data");
}
function tabSelected(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.notifyObservers(event.target.linkedBrowser.contentWindow,
"my-tab-select", "some data");
}
function contentWndLoad(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
var browser = getMostRecentBrowserWindow().getBrowser();
browser.tabContainer.addEventListener("TabOpen", tabOpened, false);
browser.tabContainer.addEventListener("TabClose", tabClosed, false);
browser.tabContainer.addEventListener("TabSelect", tabSelected, false);
}
MyJsComponent.prototype = {
/* . . . */
observe: function(aSubject, aTopic, aData) {
switch(aTopic) {
case "xpcom-startup":
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.addObserver(this, "toplevel-window-ready", false);
break;
case "toplevel-window-ready":
aSubject.addEventListener("load", contentWndLoad, false);
break;
}
}
/* . . . */
}
Also there are some additional code that you should add to handle specific cases. For instance when user close browser window you won't receive TabClose events for opened tabs in that window... And don’t forget to unregister your observers when you longer need them.