Recent Changes

Monday, February 20

  1. page Speech Recognition (Shared) edited ... ENDPROC DEF PROCconvert_to_wide(T$) FOR a=0 TO 255:multib%?a=0:NEXT SYS "MultiByteToW…
    ...
    ENDPROC
    DEF PROCconvert_to_wide(T$)
    FOR a=0 TO 255:multib%?a=0:NEXT
    SYS "MultiByteToWideChar",0,0,T$,-1,multib%,LEN(T$)
    SYS "MultiByteToWideChar",0,0,T$,-1,multib%,LEN(T$)+1
    ENDPROC
    DEF PROCcleanup
    (view changes)
    1:37 am

Sunday, February 19

  1. page Sound, Music and Video edited ... Setting speech parameters Speaking the contents of a file Speech Recognition (Shared) Vid…
    ...
    Setting speech parameters
    Speaking the contents of a file
    Speech Recognition (Shared)
    Video
    Playing an AVI file
    (view changes)
    2:06 am
  2. page Speech Recognition (Shared) edited by Rob Jeffs, February 2017 The code below demonstrates Command and Control speech recognition fo…
    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
    INSTALL @lib$+"COMLIB"
    PROC_cominit
    SYS "GetModuleHandle","OLE32.DLL" TO O%
    SYS "GetProcAddress",O%,"IIDFromString" TO `IIDFromString`
    SYS "GetProcAddress",O%,"CoTaskMemFree" TO `CoTaskMemFree`
    DIM spevent{idpt%,stream%,audio_lo%,audio_hi%,wparam%,lparam%}:REM SPEVENT structure
    DIM multib% 255:REM For converting 8 bit ASCII to 16 bit
    ON CLOSE PROCcleanup:QUIT
    ON ERROR PROCcleanup:REPORT:END
    sr%=0:rc%=0:grammar%=0:REM Object pointers
    PROCinit_speech_recog(@dir$+"GrammarColor.xml","ruleColors")
    text%=0:REM Pointer to text returned from Recognition Result
    PRINT"Listening..."
    REPEAT
    REM Poll the speech recognition event queue
    spevent.lparam%=0
    REM GetEvents by calling RecoContext method
    SYS !(!rc%+44),rc%,1,spevent{},0
    IF spevent.lparam%<>0 THEN
    REM GetText by calling a Result method (Result is object in lparam%)
    SYS !(!spevent.lparam%+20),spevent.lparam%,-1,-1,0,^text%,0
    REM Make string from GetText
    T$="":a=0
    REPEAT
    c=text%?a:a+=2:IF c<>0 THEN T$+=CHR$(c)
    UNTIL c=0
    PRINT T$
    REM Release memory used for GetText
    SYS `CoTaskMemFree`,text%
    REM lparam% contains object pointer to RecoResult
    PROC_releaseobject(spevent.lparam%)
    ENDIF
    WAIT 4
    UNTIL FALSE
    END
    DEF PROCinit_speech_recog(P$,R$)
    LOCAL C%,I%
    REM Create Shared Recognizer
    DIM C% LOCAL 15,I% LOCAL 15
    PROCconvert_to_wide("{C2B5F241-DAA0-4507-9E16-5A1EAA2B7A5C}"):REM IID_ISpRecognizer
    SYS `IIDFromString`,multib%,I%
    PROCconvert_to_wide("{3BEE4890-4FE9-4A37-8C1E-5E7E12791C1F}"):REM CLSID_SpSharedRecognizer
    SYS `CLSIDFromString`,multib%,C%
    SYS `CoCreateInstance`,C%,0,15,I%,^sr%:REM CLSCTX_ALL
    REM Create RecoContext by calling a SharedRecognizer method
    SYS !(!sr%+48),sr%,^rc%
    REM Create Grammar object by calling a RecoContext method
    SYS !(!rc%+56),rc%,0,0,^grammar%
    REM Load Grammar file (xml) by calling a Grammar method
    PROCconvert_to_wide(P$)
    SYS !(!grammar%+52),grammar%,multib%,0
    REM Set Rule State to active by calling a Grammar method
    PROCconvert_to_wide(R$)
    SYS !(!grammar%+72),grammar%,multib%,0,1
    ENDPROC
    DEF PROCconvert_to_wide(T$)
    FOR a=0 TO 255:multib%?a=0:NEXT
    SYS "MultiByteToWideChar",0,0,T$,-1,multib%,LEN(T$)
    ENDPROC
    DEF PROCcleanup
    ON ERROR OFF
    IF grammar%>0 THEN PROC_releaseobject(grammar%)
    IF rc%>0 THEN PROC_releaseobject(rc%):REM RecoContext
    IF sr%>0 THEN PROC_releaseobject(sr%):REM Shared Recognizer
    PROC_comexit
    ENDPROC
    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
    <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">
    <rule id="ruleColors" scope="public">
    <one-of>
    <item> red </item>
    <item> green </item>
    <item> yellow </item>
    <item> blue </item>
    <item> magenta </item>
    <item> cyan </item>
    <item> white </item>
    <item> black </item>
    </one-of>
    </rule>
    </grammar>

    (view changes)
    1:33 am
  3. file Recog3d.bas uploaded
    1:10 am

Sunday, February 12

Thursday, January 5

Wednesday, January 4

  1. page Exceeding the limit of 8 open files edited ... IF H% SWAP H%,!500 : SWAP E%,!532 : IF H% F% = H% = F% Please note that only the first eigh…
    ...
    IF H% SWAP H%,!500 : SWAP E%,!532 : IF H% F% = H%
    = F%
    Please note that only the first eight files will be buffered by BASIC, so files in excess of that number may be accessed a little more slowly.
    Please also be aware that the value returned by these replacement functions, for files in excess of the initial eight, is the native Windows file handle. For this to work the Windows file handle must exceed 16, otherwise BB4W will mistake it for a BASIC file channel number. This is normally reliable but there is nothing in the Microsoft API documentation which states that a file handle will always be greater than 16.

    (view changes)
    1:53 am

Tuesday, November 22

Monday, November 14

  1. page Guide to writing libraries edited ... Note: This article specifically applies to re-usable code libraries. Another use of the INSTA…
    ...
    Note: This article specifically applies to re-usable code libraries. Another use of the INSTALL statement is as a means of splitting a large program into modules. Several of the guidelines listed below do not apply to that use, apart from the prohibition on the use of line numbers and labels, and the necessity to enable the Crunch embedded program files compile option.
    A BBC BASIC for Windows LIBRARY is a special kind of program file which contains functions and/or procedures which can be called from the main program in which it is INSTALLed (or from another library installed by that same program). Fundamentally it is no different from any other program file except that it contains no 'main program' (unless you wish to include some code which will report an error if it is executed directly, see Preventing a library from being run). In addition, a library must be saved as an internal format (tokenised) .BBC file rather than a plain-text (ASCII) .BAS file. If you attempt to INSTALL a library saved in the wrong format a Bad library error will result.
    Having saidstated that a
    An overriding consideration, which lies behind many of the recommendations, is that a library must be as self-contained as possible. Ideally it should not be dependent on any specific characteristics of the program in which it is INSTALLed, nor should it impose any avoidable restrictions on that program.
    Libraries may contain neither line numbers nor labels. It follows that a library should not use GOTO, GOSUB or ON GOSUB statements. A library may use RESTORE but only the special RESTORE +n relative form.
    ...
    The shared information may be passed between the various library routines by the calling program, for example as passed-by-reference parameters or opaque structures. Using this method the functions and procedures don't communicate directly, but use the main program as an 'intermediary'.
    The functions and procedures may share information by means of PRIVATE variables, arrays and/or structures. See the article Sharing PRIVATE variables for more information.
    ...
    as incorporating the name of the library or a Globally Unique Identifier as partor the name of the name. Also consider using a specific naming conventionyour library, for library globals, such asexample globalvar@mylibrary (variable names containing (but not starting with) thean @ character.are conventionally reserved for use in libraries).
    Temporary variables (other than formal parameters) used within an individual procedure or function should always be declared as LOCAL or PRIVATE. Note that PRIVATE variables are incompatible with certain types of error trapping, in which the main program attempts to recover from an error. This is because if an error occurs at a time when a variable has been made PRIVATE you cannot call that routine again (it will be treated as a re-entrant call). This problem can be circumvented by careful use of local error trapping as follows:
    DEF PROCtest
    (view changes)
    6:15 am

Tuesday, October 25

  1. page Speeding up graphics plotting edited ... #gr gr$ Here the graphics commands have been concatenated into a single string gr$ which is t…
    ...
    #gr gr$
    Here the graphics commands have been concatenated into a single string gr$ which is then output as a single statement.
    Any number of graphics commands, within reason, can be concatenated into a single string, with the exception that a text output command (if any) must be the last thing in the string. So, when possible, the best performance will be achieved by outputting text only after everything else has been drawn, to maximise the number of commands than can be combined in a single string.
    (view changes)
    7:33 am

More