Russian language recognition in Microsoft Speech API - sapi

I would like to play a little bit with Microsoft Speech API. I have found this answer and it works! I have tried to adopt it to recognize Russian language. The grammar file look like this:
<GRAMMAR LANGID="419">
<DEFINE>
<ID NAME="TEST" VAL="1"/>
</DEFINE>
<RULE NAME="TEST" TOPLEVEL="ACTIVE">
<L>
<P>Привет</P>
<P>Пока</P>
</L>
</RULE>
</GRAMMAR>
The code is taken from the mentioned answer. But I get an error: the line
HRESULT hr = cpRecoGram->LoadCmdFromFile(L"D:\\data\\test\\reco_ru.cfg", SPLO_STATIC);
returns 0x80045052 (-2147200942): An attempt to load a CFG grammar with a LANGID different than other loaded grammars.
Is it possible to set up a program and/or an environment to use grammar files for Russian?
Environment: Windows 10 Home, Visual Studio 2017

Windows 10 does not ship a SAPI-compatible Russian recognizer as part of the OS. (There are en-US, en-GB, fr-FR, de-DE, ja-JP, zh-CHS, and zh-CHT SAPI recognizers available.)
However, if you're willing to use the Server recognizers (AKA the MS Speech Platform 11), you can find Russian recognizers at http://www.microsoft.com/en-us/download/details.aspx?id=27224.
You want the MSSpeech_SR_ru-RU_TELE.msi download.
The Server recognizers have a similar API, but don't support a number of features that the SAPI 5.4 recognizers support (namely, dictation).

For Russian
CComPtr<Speechlib_tlb::ISpRecoGrammar> cpRecoGrammar;
......
hr = cpRecoContext->CreateGrammar(1,&cpRecoGrammar);
hr = cpRecoGrammar->SetGrammarState(SPGS_DISABLED);
hr = cpRecoGrammar->ResetGrammar(0x0419);
HRESULT hr = cpRecoGram->LoadCmdFromFile(L"D:\\data\\test\\reco_ru.cfg", SPLO_STATIC);
hr = cpRecoGrammar->SetGrammarState(SPGS_ENABLED);

**for MS Speech Platform 11**
#define WM_RECOEVENT WM_USER+190
CComPtr<Speechlib_tlb::ISpRecoGrammar> cpRecoGrammar;
......
hr = cpRecoContext->CreateGrammar(1,&cpRecoGrammar);
hr = cpRecoGrammar->
SetGrammarState(Speechlib_tlb::SPGRAMMARSTATE::SPGS_DISABLED);
hr = cpRecoGrammar->ResetGrammar(0x0419);
hr = cpRecoGrammar-> LoadCmdFromFile(L"W:\\GrSR.cfg",
Speechlib_tlb::SPLOADOPTIONS::SPLO_STATIC);
hr = cpRecoGrammar->
SetGrammarState(Speechlib_tlb::SPGRAMMARSTATE::SPGS_ENABLED);
hr = cpRecoGrammar->
SetRuleState(NULL,NULL,Speechlib_tlb::SPRULESTATE::SPRS_ACTIVE);
hr = cpRecoContext->SetNotifyWindowMessage
((Speechlib_tlb::_RemotableHandle*)hWnd, WM_RECOEVENT, 0, 0)
.........

Related

How to strip the XHTML tags from the SQL query

I have this below query for Rapid 7 Nexpose SQL database and have been trying to remove xhtl,
SELECT
dp.policy_id, dp.title as policy_title, dpr.rule_id, dpr.title as policy_rule_title,
dp.benchmark_name, da.ip_address, da.host_name, dpr.description, dp.category,
fapr.date_tested, htmlToText(fapr.proof) as proof, fapr.compliance,
dpr.severity, htmlToText(dpr.rationale) as rationale, htmlToText(dpr.remediation) as remediation
FROM fact_asset_policy_rule fapr
JOIN dim_policy dp on dp.policy_id = fapr.policy_id
JOIN dim_policy_rule dpr on dpr.policy_id = fapr.policy_id and fapr.rule_id = dpr.rule_id
JOIN dim_asset da on da.asset_id = fapr.asset_id
WHERE fapr.compliance = false order by dp.title, dpr.title`
However it exports the below content for rationale and remediation with below xhtml tags which i would like to get rid off:
Rationale column example:
<xhtml:p xmlns="http://checklists.nist.gov/xccdf/1.2"
xmlns:ae="http://benchmarks.cisecurity.org/ae/0.5"
xmlns:cc6="http://cisecurity.org/20-cc/v6.1"
xmlns:cc7="http://cisecurity.org/20-cc/v7.0"
xmlns:ciscf="https://benchmarks.cisecurity.org/ciscf/1.0"
xmlns:notes="http://benchmarks.cisecurity.org/notes"
xmlns:xccdf="http://checklists.nist.gov/xccdf/1.2"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Attack surface
reduction helps prevent actions and apps that are typically used by
exploit-seeking malware to infect machines.</xhtml:p>
I would only like to get the output with TEXT "Attack surface reduction helps prevent actions and apps that are typically used by exploit-seeking malware to infect machines" and remove rest of the data.
Remediation Example:
<xhtml:div xmlns="http://checklists.nist.gov/xccdf/1.2"
xmlns:ae="http://benchmarks.cisecurity.org/ae/0.5"
xmlns:cc6="http://cisecurity.org/20-cc/v6.1"
xmlns:cc7="http://cisecurity.org/20-cc/v7.0"
xmlns:ciscf="https://benchmarks.cisecurity.org/ciscf/1.0"
xmlns:notes="http://benchmarks.cisecurity.org/notes"
xmlns:xccdf="http://checklists.nist.gov/xccdf/1.2"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xhtml:p>
<xhtml:p> To establish the recommended configuration via GP, set the
following UI path to <xhtml:span
class="inline_block">Enabled</xhtml:span> : </xhtml:p> <xhtml:code
class="code_block">Computer Configuration\Policies\Administrative
Templates\Windows Components\Windows Defender Antivirus\Windows Defender
Exploit Guard\Attack Surface Reduction\Configure Attack Surface
Reduction rules </xhtml:code> <xhtml:p> <xhtml:strong>Note:
</xhtml:strong> This Group Policy path may not exist by default. It is
provided by the Group Policy template <xhtml:span
class="inline_block">WindowsDefender.admx/adml</xhtml:span> that is
included with the Microsoft Windows 10 Release 1709 Administrative
Templates (or newer). </xhtml:p> <xhtml:p class="bold">Impact:</xhtml:p>
<xhtml:p> <xhtml:p>When a rule is triggered, a notification will be
displayed from the Action Center.</xhtml:p> </xhtml:p> </xhtml:p>
</xhtml:div>
Again need to output of remediation to be clean without XHTML and xmlns, so the clean text should look like something below:
To establish the recommended configuration via GP, set the following UI path to Enabled : Computer Configuration\Policies\Administrative Templates\Windows Components\Windows Defender Antivirus\Windows Defender Exploit Guard\Attack Surface Reduction\Configure Attack Surface Reduction rules, This Group Policy path may not exist by default. It is provided by the Group Policy template WindowsDefender.admx/adml that is included with the Microsoft Windows 10 Release 1709 Administrative Templates (or newer).
Impact: When a rule is triggered, a notification will be displayed from the Action Center.
Is there a way I can get clean HTML to text ? without the content that I don't need?
Is there a way I can get clean HTML to text?
If it is fully valid XHTML, you can cast it as XML and then select the value of the node that interests you using XPath.
declare #xhtml varchar(max)
set #xhtml = '<xhtml:div xmlns="http://checklists.nist.gov/xccdf/1.2" xmlns:ae="http://benchmarks.cisecurity.org/ae/0.5" xmlns:cc6="http://cisecurity.org/20-cc/v6.1" xmlns:cc7="http://cisecurity.org/20-cc/v7.0" xmlns:ciscf="https://benchmarks.cisecurity.org/ciscf/1.0" xmlns:notes="http://benchmarks.cisecurity.org/notes" xmlns:xccdf="http://checklists.nist.gov/xccdf/1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xhtml:p> <xhtml:p>To establish the recommended configuration via GP, set the following UI path to <xhtml:span class="inline_block">Enabled</xhtml:span> : </xhtml:p> <xhtml:code class="code_block">Computer Configuration\Policies\Administrative Templates\Windows Components\Windows Defender Antivirus\Windows Defender Exploit Guard\Attack Surface Reduction\Configure Attack Surface Reduction rules </xhtml:code> <xhtml:p> <xhtml:strong>Note:</xhtml:strong> This Group Policy path may not exist by default. It is provided by the Group Policy template <xhtml:span class="inline_block">WindowsDefender.admx/adml</xhtml:span> that is included with the Microsoft Windows 10 Release 1709 Administrative Templates (or newer). </xhtml:p> <xhtml:p class="bold">Impact:</xhtml:p> <xhtml:p> <xhtml:p>When a rule is triggered, a notification will be displayed from the Action Center.</xhtml:p> </xhtml:p> </xhtml:p> </xhtml:div>'
;with xmlnamespaces('http://www.w3.org/1999/xhtml' as xhtml)
select (cast(#xhtml as xml)).value('(//xhtml:p)[1]', 'varchar(max)')
See http://sqlfiddle.com/#!18/9eecb/136834.
Use more specific XPath if you need. For more complex requirements than "value of a single node" you can switch to XQuery, too.

nanoFramework - I2C device is not responding

New to nanoframework here, but following some sample code I'm unable to get a 7-segment display working with my ESP32 MCU.
I'm on VS 2019. Using the latest nanoframework extension (2019.5.0.14). My project is very simple, using these packages:
<package id="nanoFramework.CoreLibrary" version="1.10.1-preview.11" targetFramework="netnanoframework10" />
<package id="nanoFramework.Runtime.Events" version="1.9.0-preview.14" targetFramework="netnanoframework10" />
<package id="nanoFramework.Windows.Devices.I2c" version="1.4.1-preview.29" targetFramework="netnanoframework10" />
I've even tried simplifying the code down to just this:
I2cDevice _display = I2cDevice.FromId("I2C1", new I2cConnectionSettings(0x70) { BusSpeed = I2cBusSpeed.FastMode });
_display.Write(new byte[] { 0x21 });
What I've tried:
Verifying that 0x70 is the correct I2C bus address (yes it is)
Using the same 7-segment display and MCU with sample project in Arudino IDE (works fine)
Step debugging in VS to see if any errors are thrown (nothing errors out)
What am I missing?
For future reference, what resolved the issue for me was reassigning other GPIO pins (14 and 15) to SDA/SCL with:
Configuration.SetPinFunction(14, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(15, DeviceFunction.I2C1_CLOCK);
Answering this in our Discord server.

Expert advisor in different trader platform

I would like to know, if I code an EA in a normal metatrader4 platform, can I reuse the .ex4 in other trading platform for example InstaTrader?
The reason is that, when I have created a new EA in InstaTrader, the EA code generated from InstaTrader is different from the one generated from metatrader4. And I couldn't find any documentation regarding to InstaTrader's EA.
Not sure anyone has encountered this before?
No. MQL is the language specifically for meta-editor which is a member of meta-trader platform.
Other trading languages may have their own scripting languages.
Metatrader4
In principle Metatrader4 uses a Metalang.exe that compiles the MQL4-source-code files into an "internally"-executable format EX4
As defined, EX4 is binary-executable on all Metatrader4 terminals.
.
WhiteLabel-ed Terminals
InstaTrader(TM) and many other *-Trader(TM)-s are so called White-Label modifications of the same MetaQuotes, Inc., software product, the [Metatrader 4 Terminal], that are just individually "skinned" in a name of the respective Broker, who has bought from the MetaQuotes, Inc. the license for a suite of [Metatrader 4 Server + Metatrader 4 Risk Management + Metatrader 4 Dealer Desk + ... ], inclusive, but not limited to, the right to re-label the client Terminal program.
Thus under most of the situations your EX4 code shall run on any other re-labeled Terminal
But...
Restrictions on binary-compatibility apply, as Metatrader4 terminals gets released in so called Builds, ( Build 432 -> Build 468 -> Build 509 -> ... -> Build 600 -> Build 624 ) and some of these have also modified the binary-code format.
Thus the EX4 code shall be hosted on a "similar" generation of the Terminal Build
Finally...
The ultimate show-stopper is the MetaQuotes, Inc., licensing policy, which makes a server-side locking to take place [Metatrader 4 Server] has a setting to reject connection requests from client Terminals in case their Build # is lesser than a treshold set on Server side.
There the SLM story ends. Forever.

QuickBooks API Invoice <DueDate> tag

I wrote a custom integration between a SQL Server based system and QuickBooks many years ago which automatically creates invoices in QuickBooks from data in SQL Server. The XML string to create the invoices is quite simple:
<QBXML>
<QBXMLMsgsRq newMessageSetID="10025027" onError="continueOnError">
<InvoiceAddRq requestID="10025027">
<InvoiceAdd>
<CustomerRef>
<FullName>Acme Corporation, Inc.</FullName>
</CustomerRef>
<TxnDate>2014-02-05</TxnDate>
<RefNumber>124</RefNumber>
<ShipAddress>
<Addr1>16-01 16th Avenue, Dock 3</Addr1>
<Addr2/>
<Addr3/>
<Addr4/>
<City>Astoria</City>
<State>NY</State>
<PostalCode>11105</PostalCode>
</ShipAddress>
<PONumber> 6028019</PONumber>
<SalesRepRef>
<FullName>H</FullName>
</SalesRepRef>
<Memo>1401106</Memo>
<InvoiceLineAdd>
<ItemRef>
<FullName>SALES</FullName>
</ItemRef>
<Desc> Semi Annual Sampling - M1; Day 1</Desc>
<Rate>5580</Rate>
</InvoiceLineAdd>
</InvoiceAdd>
</InvoiceAddRq>
</QBXMLMsgsRq>
</QBXML>
The SQL Server based system actually prints detailed invoices which are delivered to the customer, QuickBooks is only used to keep track of account balances and payments. I am now trying to add the DueDate to the invoice by adding the following XML tag:
<DueDate>2014-03-07</DueDate>
I have tried to place this tag in several places in the XML string but QuickBooks rejects the request with the following error:
"QuickBooks found an error when parsing the provided XML text stream."
The bookkeeper is able to manually change the due date on the invoices after they are created, but for some reason I can't specify the due date when creating the invoices with the QuickBooks API. Any Ideas?
Thanks.
A few things to note here:
This is an incomplete qbXML request. There should be an XML and qbXML header tag as the very first two lines, and you're missing them. They should look like this:
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
That version="..." bit should be set to something your version of QuickBooks supports (generally your QuickBooks version - 1, e.g. QuickBooks 2012 supports qbXML version 11.0, QuickBooks 2013 supports qbXML version 12.0, QuickBooks 2014 supports qbXML version 13.0, etc.)
Your post doesn't even show the DueDate field in the XML, so it's a little hard to tell what's actually wrong, but...
Keep in mind that the order of tags in qbXML is important. So if the OSR shows the DueDate field after PONumber, you better make darn sure to put it after the PONumber field. If you put it before it, you're going to get exactly the error you described.
Did you use the OSR to find the correct place? There shouldn't be any guess-work here - it tells you exactly where to put it.
...
<State>NY</State>
<PostalCode>11105</PostalCode>
</ShipAddress>
<PONumber> 6028019</PONumber>
<DueDate>2014-02-12</DueDate
<SalesRepRef>
<FullName>H</FullName>
</SalesRepRef>
<Memo>1401106</Memo>
...
I think the missing header tags were the problem. (I also added the <TermsRef> tag)
Here is the XML that did the trick:
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="11.0"?>
<QBXML>
<QBXMLMsgsRq newMessageSetID="10025079" onError="continueOnError">
<InvoiceAddRq requestID="10025079">
<InvoiceAdd>
<CustomerRef>
<FullName>Acme Corporation</FullName>
</CustomerRef>
<TxnDate>2014-02-13</TxnDate>
<RefNumber>168</RefNumber>
<ShipAddress>
<Addr1>Acme Corporation</Addr1>
<Addr2>1587-43 Veteran's Highway</Addr2>
<Addr3/>
<Addr4/>
<City>Islandia</City>
<State>NY</State>
<PostalCode>11749</PostalCode>
</ShipAddress>
<PONumber>5A873929B</PONumber>
<TermsRef>
<FullName>30 Days</FullName>
</TermsRef>
<DueDate>2014-03-15</DueDate>
<SalesRepRef>
<FullName>H</FullName>
</SalesRepRef>
<Memo>1402016</Memo>
<InvoiceLineAdd>
<ItemRef>
<FullName>SALES</FullName>
</ItemRef>
<Desc> OBAR Auto Parts, 279 South Street, Oyster Bay, NY 11771</Desc>
<Rate>1760</Rate>
</InvoiceLineAdd>
</InvoiceAdd>
</InvoiceAddRq>
</QBXMLMsgsRq>
</QBXML>
Thank you again!

Can you prevent SndVol from displaying empty audio session?

I've been playing around with Vista's CoreAudio stuff, in particular IAudionSessionEvents, with the goal of monitoring the default audio session for changes to volume caused by loaded code.
However, it looks like as soon as you install an IAudioSessionEvents listener SndVol lists the program with all associated volume controls. As a good portion of the time no code has been loaded that will actually play anything, this is less than ideal.
Basically, is there some way to monitor the default audio session without causing SndVol to list it?
A solution for Vista is preferred, but something depending on new apis provided in Windows 7 is better than nothing.
Larry Osterman pointed out the ISessionManager2 and IAudioSessionNotification interfaces added in Windows 7. However, I never receive notice of new session. Is anyone aware of gotchas or problems with this API under Windows 7 build 7000?
Code registering IAudioSessionNotifications, omitting lots of error checking code*:
BOOL success = false;
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
IAudioSessionManager2* pManager = NULL;
IClassFactory* pFactory = NULL;
hr = CoInitialize(NULL);
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&pManager);
listener = NULL;
hr = CoGetClassObject(CLSID_CustomFactory, CLSCTX_ALL, NULL, __uuidof(IClassFactory), (void**)&pFactory);
hr = pFactory->CreateInstance(NULL, __uuidof(IAudioSessionNotification), (void**)&listener);
hr = pManager->RegisterSessionNotification(listener);
*While not the purpose of this question, constructive critic of my COM code is welcome.
If you want to monitor the audio session stuff, you should use the IAudioSessionManager interface to retrieve your IAudioSessionControl object. A session only shows up in SndVol when it transitions from the inactive to the active state - that happens when when someone calls IAudioClient::Start() - as long as you don't call IAudioClient::Start you shouldn't get a session slider.
In Windows 7, there are a new set of APIs (IAudioSessionManager2) that allow you to listen for session creation and destruction.
Also for Windows 7, there is the AUDCLNT_SESSIONFLAGS_HIDE flag (the documentation for this hasn't been updated yet but it's in the headers)