User Tools

Site Tools


speech_20recognition_20_28shared_29

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

speech_20recognition_20_28shared_29 [2018/03/31 13:19]
127.0.0.1 external edit
speech_20recognition_20_28shared_29 [2018/04/15 12:58] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Speech Recognition (Shared)===== =====Speech Recognition (Shared)=====
  
-//by Rob Jeffs, February 2017//\\ \\  The code below demonstrates Command and Control speech recognition for a Shared Recognizer, via the API route (not COM automation/​ActiveX). Although, confusingly,​ the first unavoidable step is to create an instance of a speech recognizer object using COM automation!\\ \\  Microsoft'​s online documentation provided the basis for this demonstration,​ including examples of xml Grammar files. The documentation contains object method lists in VTable order, which relate to the offsets in the SYS commands below; however, be aware that method tables include methods inherited from other objects.\\ \\  When running the code, the operating system may open a set-up wizard if speech recognition hasn't been used before. Because we're using a shared recognizer, this means that the desktop and other applications may also be listening for commands spoken by the user. A small 'User Interface'​ should appear, through which the microphone can be turned on and off. A related menu can be accessed via the icon bar, and it may be necessary to adjust the speech recognition language to English-US via the Control Panel / Advanced Speech Options. (The best results were obtained using a plug in microphone, without training.)\\ \\  Note: IIDFromString and CLSIDFromString perform identical functions\\ \\ +//by Rob Jeffs, February 2017//\\ \\  The code below demonstrates Command and Control speech recognition for a Shared Recognizer, via the API route (not COM automation/​ActiveX). Although, confusingly,​ the first unavoidable step is to create an instance of a speech recognizer object using COM automation!\\ \\  Microsoft'​s online documentation provided the basis for this demonstration,​ including examples of xml Grammar files. The documentation contains object method lists in VTable order, which relate to the offsets in the SYS commands below; however, be aware that method tables include methods inherited from other objects.\\ \\  When running the code, the operating system may open a set-up wizard if speech recognition hasn't been used before. Because we're using a shared recognizer, this means that the desktop and other applications may also be listening for commands spoken by the user. A small 'User Interface'​ should appear, through which the microphone can be turned on and off. A related menu can be accessed via the icon bar, and it may be necessary to adjust the speech recognition language to English-US via the Control Panel / Advanced Speech Options. (The best results were obtained using a plug in microphone, without training.)\\ \\  Note: IIDFromString and CLSIDFromString perform identical functions 
 + 
 +<code bb4w>
    ​INSTALL @lib$+"​COMLIB"​    ​INSTALL @lib$+"​COMLIB"​
    ​PROC_cominit    ​PROC_cominit
Line 21: Line 23:
    ​REPEAT    ​REPEAT
  
-   REM Poll the speech recognition event queue +     REM Poll the speech recognition event queue 
-   ​spevent.lparam%=0 +     ​spevent.lparam%=0 
-   ​REM GetEvents by calling RecoContext method +     ​REM GetEvents by calling RecoContext method 
-   ​SYS !(!rc%+44),​rc%,​1,​spevent{},​0 +     ​SYS !(!rc%+44),​rc%,​1,​spevent{},​0 
-   ​IF spevent.lparam%<>​0 THEN +     ​IF spevent.lparam%<>​0 THEN 
-   ​REM GetText by calling a Result method (Result is object in lparam%) +       ​REM GetText by calling a Result method (Result is object in lparam%) 
-   ​SYS !(!spevent.lparam%+20),​spevent.lparam%,​-1,​-1,​0,​^text%,​0 +       ​SYS !(!spevent.lparam%+20),​spevent.lparam%,​-1,​-1,​0,​^text%,​0 
-   ​REM Make string from GetText +       ​REM Make string from GetText 
-   ​T$="":​a=0 +       ​T$="":​a=0 
-   ​REPEAT +       ​REPEAT 
-   ​c=text%?​a:​a+=2:​IF c<>0 THEN T$+=CHR$(c) +         ​c=text%?​a:​a+=2:​IF c<>0 THEN T$+=CHR$(c) 
-   ​UNTIL c=0 +       ​UNTIL c=0 
-   ​PRINT T$ +       ​PRINT T$ 
-   ​REM Release memory used for GetText +       ​REM Release memory used for GetText 
-   ​SYS `CoTaskMemFree`,​text% +       ​SYS `CoTaskMemFree`,​text% 
-   ​REM lparam% contains object pointer to RecoResult +       ​REM lparam% contains object pointer to RecoResult 
-   ​PROC_releaseobject(spevent.lparam%) +       ​PROC_releaseobject(spevent.lparam%) 
-   ​ENDIF+     ​ENDIF
  
-   WAIT 4+     WAIT 4
    UNTIL FALSE    UNTIL FALSE
    END    END
Line 76: Line 78:
    ​PROC_comexit    ​PROC_comexit
    ​ENDPROC    ​ENDPROC
 +</​code>​
        
-\\ \\  ​Here's the xml source required for recognizing the names of BASIC colours. It can be entered via Notepad and should be saved as GrammarColor.xml\\ \\ +Here's the xml source required for recognizing the names of BASIC colours. It can be entered via Notepad and should be saved as GrammarColor.xml 
 + 
 +<code xml>
   <grammar version="​1.0"​ xml:​lang="​en-UK"​ mode="​voice"​ root="​ruleColors"​ xmlns="​http://​www.w3.org/​2001/​06/​grammar"​ tag-format="​semantics/​1.0">​   <grammar version="​1.0"​ xml:​lang="​en-UK"​ mode="​voice"​ root="​ruleColors"​ xmlns="​http://​www.w3.org/​2001/​06/​grammar"​ tag-format="​semantics/​1.0">​
  
Line 94: Line 99:
  
   </​grammar>​   </​grammar>​
 +</​code>​
speech_20recognition_20_28shared_29.txt · Last modified: 2018/04/15 12:58 by richardrussell