The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Magnum on December 11, 2011, 12:21:03 AM

Title: Voice recognition code
Post by: Magnum on December 11, 2011, 12:21:03 AM
There are a few voice recognition samples here, but this is the shortest if you don't count the Constants.

Can someone test this on Win 7.

Would it work on Win 95 - XP ?


; SpVoice Simple example  By G-Spider 2010

.586
.model flat,stdcall
option casemap:none
  include /masm32/include/windows.inc
  include /masm32/include/kernel32.inc
  include /masm32/include/user32.inc
  include /masm32/include/ole32.inc

  includelib /masm32/lib/kernel32.lib
  includelib /masm32/lib/user32.lib
  includelib /masm32/lib/ole32.lib

.data

TEXT    dw 'M','e','r','r','y',' ','C','h','r','i','s','t','m','a','s',' ','t','o',' ','e','v','e','r','y','o','n','e','.',0

.data?

lpSpVoiceCOM    dd ?

.const

CLSID_SpVoice GUID <096749377h, 03391h, 011D2h, <09Eh, 0E3h, 000h, 0C0h, 04Fh, 079h, 073h, 096h>>
IID_ISpVoice  GUID <06C44DF74h, 072B9h, 04992h, <0A1h, 0ECh, 0EFh, 099h, 06Eh, 004h, 022h, 0D4h>>

ISpNotifySource  STRUCT
SetNotifySink              DWORD   ?
SetNotifyWindowMessage     DWORD   ?
SetNotifyCallbackFunction  DWORD   ?
SetNotifyCallbackInterface DWORD   ?
SetNotifyWin32Event        DWORD   ?
WaitForNotifyEvent         DWORD   ?
GetNotifyEventHandle       DWORD   ?

ISpNotifySource  ENDS

ISpEventSource  STRUCT
SpNotifySource      ISpNotifySource   <>
SetInterest         DWORD   ?
GetEvents           DWORD   ?
GetInfo             DWORD   ?
ISpEventSource  ENDS

ISpVoiceVtbl        STRUCT
; IUnknown methods
QueryInterface       DWORD   ?
AddRef               DWORD   ?
Release              DWORD   ?
SpEventSource        ISpEventSource   <>
SetOutput            DWORD   ?
GetOutputObjectToken DWORD   ?
GetOutputStream      DWORD   ?
_Pause               DWORD   ?
Resume               DWORD   ?
SetVoice             DWORD   ?
GetVoice             DWORD   ?
Speak                DWORD   ?
SpeakStream          DWORD   ?
GetStatus            DWORD   ?
Skip                 DWORD   ?
SetPriority          DWORD   ?
GetPriority          DWORD   ?
SetAlertBoundary     DWORD   ?
GetAlertBoundary     DWORD   ?
SetRate              DWORD   ?
GetRate              DWORD   ?
SetVolume            DWORD   ?
GetVolume            DWORD   ?
WaitUntilDone        DWORD   ?
SetSyncSpeakTimeout  DWORD   ?
GetSyncSpeakTimeout  DWORD   ?
SpeakCompleteEvent   DWORD   ?
IsUISupported        DWORD   ?
DisplayUI            DWORD   ?
ISpVoiceVtbl ENDS

ISpVoice    STRUCT
   lpVtbl            DWORD   ?
ISpVoice   ENDS

.code

start:

   invoke CoInitialize,0
   invoke CoCreateInstance,offset CLSID_SpVoice, 0,CLSCTX_INPROC_SERVER, offset IID_ISpVoice,offset lpSpVoiceCOM

   .if eax == 0   

       push 100   ;USHORT Volume0~100
       mov eax,lpSpVoiceCOM
       push eax   ;<===Note!
       mov eax,[eax]
       call [eax].ISpVoiceVtbl.SetVolume

       ;lpSpVoiceCOM->Speak(L"Golden Spider", 0, 0)//; c++
       ;lpSpVoiceCOM->lpVtbl->Speak(lpSpVoiceCOM,L"I LOVE YOU!", 0, 0)//; pure c

       push 0
       push 0
       push offset TEXT
       mov eax,lpSpVoiceCOM
       push eax   
       mov eax,[eax].ISpVoice.lpVtbl  ;equ  mov eax,[eax]     
       call [eax].ISpVoiceVtbl.Speak  ;call DWORD PTR[eax+50h]
       
       mov eax,lpSpVoiceCOM
       push eax
       mov eax,[eax]
       call [eax].ISpVoiceVtbl.SpEventSource.SpNotifySource.SetNotifyWin32Event
   
       ;// release ISpVoice COM interfaces
       ;lpSpVoiceCOM->lpVtbl->Release(lpSpVoiceCOM)

       mov eax,lpSpVoiceCOM
       push eax
       mov eax,[eax]
       call [eax].ISpVoiceVtbl.Release
       
       mov  lpSpVoiceCOM,0
   .endif
   
    invoke   CoUninitialize
   
invoke ExitProcess,0

end start
Title: Re: Voice recognition code
Post by: jj2007 on December 11, 2011, 01:00:40 AM
Works fine on XP SP3, Andy.
Title: Re: Voice recognition code
Post by: bomz on December 11, 2011, 01:16:07 AM
voice recognition - I am shocked.
This is voice text reader, with using windows Text-to-speech engine

I have already acronis backup of Windows NT4.0, Windows 98, Windows 2000 and Windows 7. but it's a long story . It's better to read have it text-to-speech engine or not

You may always put dll from XP near your application

Here Russian fun club of Windows 98 you may ask to try your code
http://forum.ru-board.com/topic.cgi?forum=62&topic=21298&start=2380
Here Windows NT 4. but there is no user. It's rarely used for server
http://forum.ru-board.com/topic.cgi?forum=35&bm=1&topic=3631&start=200#lt
Title: Re: Voice recognition code
Post by: MichaelW on December 11, 2011, 02:06:38 AM
Under Windows 2000 CoCreateInstance returns 80040154h, REGDB_E_CLASSNOTREG (Class not registered).

Title: Re: Voice recognition code
Post by: bomz on December 11, 2011, 02:11:05 AM
QuoteUnder Windows 2000
no need go low - 98,  NT, 95
put ole32.dll in application directory http://zalil.ru/32245213
there is many alternative text-to-speech engines which know different languages and have man and woman voices
Title: Re: Voice recognition code
Post by: MichaelW on December 11, 2011, 02:33:36 AM
Under Windows 2000 I solved the problem by installing  Microsoft Speech SDK 5.1 (http://www.microsoft.com/downloads/details.aspx?FamilyID=5E86EC97-40A7-453F-B0EE-6583171B4530&amp;amp;displaylang=e&displaylang=en)
Title: Re: Voice recognition code
Post by: jj2007 on December 11, 2011, 02:56:45 AM
Quote from: bomz on December 11, 2011, 01:16:07 AM
voice recognition - I am shocked.

Me too, but you are right it's TTS. What worries me more is that I can't get any Lernout & Hauspie voices to work. They don't appear in the Control Panel speech options. Just Microsoft Sam & Mike & Mary.

L&H is SAPI 4, that might be the problem. Fully incompatible with 5.1...
Title: Re: Voice recognition code
Post by: Magnum on December 11, 2011, 03:12:45 AM
I am currently downloading the package that contains M.S. Mary's voice since I run XP.

Microsoft Larry's voice ain't cutting it, it sounds like the one that the old Soundblaster boards used to use.

I hope I can get it to work.

A lot of times it's a BIG production given Microsoft terse documentation.  :bdg

I don't have a speech icon in Control Panel, is that something that started with Vista ?
Title: Re: Voice recognition code
Post by: sinsi on December 11, 2011, 03:33:37 AM
Works OK in win7 pro x64 and win8 preview x64.
Title: Re: Voice recognition code
Post by: MichaelW on December 11, 2011, 07:35:58 AM
Andy,

My Windows 2000 has a speech icon in Control Panel, and I'm fairly certain that the Microsoft Speech SDK put it there.

Try looking in your registry for HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices. If the branch is not there then you might try installing the SDK.
Title: Re: Voice recognition code
Post by: Bill Cravener on December 11, 2011, 10:55:49 AM
Dougie Murray did up a great example of text to speech, I modified it slightly to simplify it just a bit years back.

You can get the example here from this old thread.

http://www.masm32.com/board/index.php?topic=9024.0
Title: Re: Voice recognition code
Post by: Magnum on December 11, 2011, 01:39:00 PM
Dougie example showed me that I have sapi.cpl.

For some reason, it isn't in my Control Panel.

Haven't had any luck determining why.

I will see if TwekUi can help.

I made a shortcut.
Title: Re: Voice recognition code
Post by: Farabi on December 12, 2011, 06:45:44 AM
There is somebody who post about FFT. Interested to be researcher in here?  :cheekygreen:
Title: Re: Voice recognition code
Post by: jj2007 on December 12, 2011, 03:41:24 PM
Folks, go the Loquendo demo page (http://www.loquendo.com/en/demo-center/tts-demo/). Fantastic. Unfortunately those voices cost a fortune ::)
Title: Re: Voice recognition code
Post by: Farabi on December 17, 2011, 01:15:13 AM
Anyway there is 44100 sample each second where each sample is 16-bit code.
Title: Re: Voice recognition code
Post by: Magnum on December 23, 2011, 01:26:38 AM
When I increase the length of the string, the assemblers gives these messages.

C:\masm32\SOURCE\jak.asm(17) : error A2042:statement too complex
C:\masm32\SOURCE\jak.asm(103) : error A2006:undefined symbol : TEXT
Title: Re: Voice recognition code
Post by: dedndave on December 23, 2011, 03:13:02 AM
try splitting the TEXT string into seperate lines
not a wonderful name, by the way   :P
_TEXT is the old name for the code segment in C programs
Title: Re: Voice recognition code
Post by: Magnum on December 23, 2011, 11:58:53 AM
That did the trick.