[bb] Speech input for Blitz! by Beeps [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:39

Previous topic - Next topic

BlitzBot

Title : Speech input for Blitz!
Author : Beeps
Posted : 1+ years ago

Description : Grab your microphone - Blitz input will never be the same again! Requires the Speech libs from Microsoft ( Search www.microsoft.com for SAPI 5.1 )

Download the zipped userlib with examples at www.binary-people.com/downloads/simplespeech.zip


Code :
Code (blitzbasic) Select
Examples of use....

;training

Text 10,440,"repeat the words when prompted"

If VoiceInit()=0 Then
   End
EndIf

Type word
   Field original$
   Field id
End Type

Type altword
   Field id
   Field alt$
   Field hits
End Type

makeword("up",0)
makeword("down",1)
makeword("left",2)
makeword("right",3)
makeword("blue",4)
makeword("red",5)
makeword("clear",6)
makeword("green",7)
makeword("stop",8)
makeword("quit",9)

maxword=9

While True
   
   For wd.word=Each word
      If wdid=iword Then
         Exit
      EndIf
   Next
   Cls
   Color 255,255,255
   Text 10,10,"Please say " + wdoriginal
   icount = 2
   For fd.altword = Each altword
      If fdid=wdid Then
         Text 10,icount*20,fdalt + " - " + fdhits
         icount=icount+1
      EndIf
   Next
   
   Delay 100
   a$=""
   If VoiceBlockForResult()=1 Then
      a$ = Lower(VoiceTestBlock())
   EndIf
   
   If a$="" Then
      ;Stop
   Else
      found=False
      For tw.altword=Each altword
         If twid=iword And twalt=a$ Then
            twhits=twhits+1
            found=True
         EndIf
      Next
      If found=False Then
         aw.altword = New altword
         awid =iword
         awalt= a$
      EndIf
      iword=iword+1
      If iword>maxword Then iword=0
   EndIf

   Delay 10
   
   If GetKey()<>0 Then
      savewordlist()
      VoiceShutdown
      End
   EndIf
Wend

End

Function makeword(thisword$,id)
   a.word=New word
   aoriginal=thisword
   aid=id
End Function

Function savewordlist()
   file=WriteFile ("word.txt")
   For wd.word = Each word
      ;save the word setcion header
      WriteLine file,"#"
      WriteLine file,wdid
      WriteLine file,wdoriginal
      For aw.altword=Each altword
         ;save each alternative
         If awid = wdid Then
            WriteLine file,awalt
         EndIf
      Next
   Next
   WriteLine file,"#"

   CloseFile file
End Function



;;simple drawing snake game thing....

Graphics 640,480,0,2

x=160
y=120

Color 255,255,255

R=255
g=0
b=0

Text 10,10,"initializing..."
If VoiceInit()=0 Then
   End
EndIf

loadwordlist()

Rect x,y,10,10,True

;VoiceSay("Welcome to speech draw 1")

test=True
aa$="say something"
While test

   
   If VoiceBlockForResult()=1 Then
      a$ = VoiceTestBlock()
      aa$ = a$
   Else
      a$=""
   EndIf
   
   Color 255,255,255
   ;Text 10,10,icount
   Color 0,0,0
   Rect 0,350,120,420,1
   Color 255,255,255
   Text 10,400,aa$
   ;Delay 1000
   
   thisid=getwordid(aa$)
   Select thisid;Lower(a$)
      Case 0;"up","a","cop"
         dir=1
      Case 1;"down"
         dir=3
      Case 2;"left"
         dir=4
      Case 3;"right"
         dir=2
      Case 5
         r=255
         g=0
         b=0
      Case 4
         r=0
         g=0
         b=255
      Case 7
         r=0
         g=255
         b=0
      Case 8
         dir=0
      Case 9
         Print "finishing up"
         VoiceShutdown()
         
         End
   End Select
   
   If GetKey()<>0
      Print "finishing up"
         
         VoiceShutdown()
         End
   EndIf
   
   Select dir
      Case 1
         y=y-1
      Case 2
         x=x+1
      Case 3
         y=y+1
      Case 4
         x=x-1
   End Select
   
   Color r,g,b
   Rect x,y,10,10,True
   icount=icount + 1
   Text 10,40,"up,down,left,right,blue,"
   Text 10,60,"red,green,clear,stop,quit"
   fade(True,0,1,0,0)
   Delay 1
   
   If KeyHit(1) Then test=False
Wend

VoiceShutdown()

End


Function fade(fadein=False,pause=0,inc=10,xpos=0,ypos=0)
   ;image1=image to fade in or out
   ;fadein(default false) - is image to fade in or out?
   ;pause= delay between frames
   ;inc= how many colour points to jump per frame
   ;x and y pos are position of image

;   setup limits etc
;   ti=CopyImage (image1)
   wd=320;ImageWidth(ti)
   ht=256;ImageHeight(ti)
   
   
;   For icount=0 To 255/inc
   ;fade an image out to black      
      SetBuffer FrontBuffer();ImageBuffer(ti)
      LockBuffer FrontBuffer();ImageBuffer(ti)
      For x=0 To wd-1
         For y=0 To ht-1
            ;fade pixels to black
            argb=ReadPixelFast (x,y,FrontBuffer());ImageBuffer(ti))
             
            tr=(argb Shr 16) And $ff
            tg=(argb Shr 8) And $ff
            tb=argb And $ff
             
            tr=tr - inc
            tg=tg - inc
            tb=tb - inc
             
            If tr<0 Then tr=0
             
            If tg<0 Then tg=0
             
            If tb<0 Then tb=0
             
            newargb=((tr Shl 16) Or (tg Shl 8) Or tb)
   
            WritePixelFast x,y,newargb,FrontBuffer();ImageBuffer(ti)
         Next
      Next
      UnlockBuffer FrontBuffer();ImageBuffer(ti)
       
      SetBuffer FrontBuffer()
;      Cls
;      DrawImage ti,xpos,ypos
;      Flip
;      Delay pause
;   Next
   
;   FreeImage ti
;   ti=0
End Function


Type word
   Field original$
   Field id
End Type

Type altword
   Field id
   Field alt$
   Field hits
End Type


Function getwordid(a$)
   a$=Lower(a$)
   For wd.word=Each word
      If wdoriginal = a$
         Return wdid
      EndIf
   Next
   
   For tw.altword=Each altword
      If twalt=a$ Then
         Return twid
      EndIf
   Next
   Return -1
End Function

Function loadwordlist()
   file=ReadFile ("word.txt")

   temp$=ReadLine(file)
   
   While Not Eof(file)
      If temp$="#"
         ;start new word
         wd.word=New word
         wdid=ReadLine (file)
         wdoriginal=ReadLine(file)
         temp=""
         
         Repeat
            ;add all alt words
            temp$=ReadLine(file)
            td.altword=New altword
            tdid=wdid
            tdalt=temp
         
         Until temp$="#"    
      EndIf
   Wend

   CloseFile file
End Function


Comments :


Klaas(Posted 1+ years ago)

 Sounds great ... but wich files i need (Requires the Speech libs from Microsoft) to run it ?


xmlspy(Posted 1+ years ago)

 This is awesome, thanks dude


Beeps(Posted 1+ years ago)

 you can find the files from the M$ website at... www.microsoft.com/downloads/details.aspx?FamilyID=5e86ec97-40a7-453f-b0ee-6583171b4530&displaylang=en I used the 70mb download but I needed this to create the userlib, there's an msi installation file but I don't know how to use it OR get it into an install for use by another person. Any light anyone can shed on this would be great :) Also, in the control panel if you go to speech and train your machine to understand your voice (until you get sick of it) you'll find the userlib works much better.


Klaas(Posted 1+ years ago)

 Wohoo ... this is fun ... thanks a lot.Well, my english must sound awfull ... cause the litle dot does everything except what i told him to do :-)


Beeps(Posted 1+ years ago)

 Here's the deal with the little dot app. Run the training one through about 5 times for each word (it repeats) then hit a key (not [esc]), this saves a list of all the words the speech userlib 'thinks' you said while saying the words that flashed on screen. When you run the snakey dot thing (in the same dir) it maps what you say to those words like a lookup - making the snake respond better the longer you train it :) Hope that helps.


Klaas(Posted 1+ years ago)

 well, i knowDid you know what those .msm files for ? ... this installation file of the speech sdk is english language only i think. Is there a way to use this for other languages too ?


Beeps(Posted 1+ years ago)

 I think there's language packs on that Microsoft page, not sure though.


Beeps(Posted 1+ years ago)

 Jay Mattis updated this in the forum, here's what he said...Ok, I added commands to the library. VoiceInit now takes a string. If you run VoiceInit("") it will run just like the original version. Otherwise, you need to pass the filepath to your commandset. SAPI has an XML standard for writing in new commands and phrases and whatnot. Search the internet. So, write your XML file and then use gc.exe provided with the SAPI SDK to compile your XML to a CFG file. Then use VoiceInit like this: VoiceInit("C:mycommands.cfg") and it will load your commands instead of the universal dictionary. Have fun! www.cowgames.com/sapiuserlib.zip


asdfasdf(Posted 1+ years ago)

 Blitz says there is two type word and type wordinti


asdfasdf(Posted 1+ years ago)

 What is the file called that you need to download?


_PJ_(Posted 1+ years ago)

 Until I see an idiot's (and I mean PROPER I D I O T ) and a fully working example, Ive given up - the only reminder I have of this functionality is ctfmon running on startup everytime!


Picklesworth(Posted 1+ years ago)

 Hey, this would work great for a feature in a sci-fi space flight game (which I just so happen to be planning) if it is what I think it is. You could talk to your ship like in Star Trek and tell it to adjust shields, or divert power to weapons, etc. If it was for a purposefully cheezy one, then the voice recognition would be even better because of its common failure rate unless properly calibrated.That would save people who don't like memorizing controls a bit of time!I also just thought of how this could help people with lip syncronization, even if it gets the words wrong.So, very handy dll, thank you. And it looks like microsoft has once again proven to actually be quite generous (if you ignore the very frghteningly confusing license).


.rIKmAN.(Posted 1+ years ago)

 Whats the deal with using this in our projects, freeware, commercial, not at all cos of M$ and the SAM licence...?


Ked(Posted 1+ years ago)

 The binary-people link doesn't work anyone have an idea onhow to make the userlibs??? Someone help me please!


Compt-Man(Posted 1+ years ago)

 The binary-people link doesn't work anyone have an idea onhow to make the userlibs??? Someone help me please!


Panno(Posted 1+ years ago)

 same here !


Matty(Posted 1+ years ago)

 It didn't really work properly even when the link wasn't dead.  Would have been nice though...


hunulullu(Posted 1+ years ago)

 someone still got the files?please upload or send me to hunulullu{at}gmx{dot]de


markcw(Posted 1+ years ago)

 Try "So To Speak" by semar, it's written in BlitzPlus and uses a DLL made by Metalman. I'm not sure but it's probably compatible with Blitz3D.Download the exe, dll and complete source code here:<a href="http://www.sergiomarcello.com/so_to_speak/so_to_speak.html" target="_blank">http://www.sergiomarcello.com/so_to_speak/so_to_speak.html</a>Edit: for speech input I think you can use MSAgent.


ZJP(Posted 1+ years ago)

 
www.binary-people.com/downloads/simplespeech.zip
www.cowgames.com/sapiuserlib.zip
Hi,Dead links :(Someone has these files? Malice? Picklesworth?Please send me to zjp@...JP


_PJ_(Posted 1+ years ago)

 I'm not sure, I didn't get very far with this and have re-installed  don't know how many times since... I'll have a look for you, ZJP...Okay, sent... let me know that you received them okay, my email client likes to remove attachments :)


ZJP(Posted 1+ years ago)

 Hi,Receive ok. The .decls is "empty" :(Thx a lot. ;)JP


Guy Fawkes(Posted 1+ years ago)

 yes, i need them too mate. why not upload to <a href="http://mediafire.com/" target="_blank">http://mediafire.com</a>


Guy Fawkes(Posted 1+ years ago)

 i have located the sdk file: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=5E86EC97-40A7-453F-B0EE-6583171B4530&displaylang=en#filelist" target="_blank">http://www.microsoft.com/downloads/details.aspx?FamilyId=5E86EC97-40A7-453F-B0EE-6583171B4530&displaylang=en#filelist</a>what dll and where to get the decls, idk..


Guy Fawkes(Posted 1+ years ago)

 does anyone have the files for this?


Guy Fawkes(Posted 1+ years ago)

 can someone please post the files for this?


markcw(Posted 1+ years ago)

 Send Malice an email.


_PJ_(Posted 1+ years ago)

 As ZJP states, and as I didn't know prior to his response here, the decls file I had is empty. :(The dll itself should be available with windows or via Microsoft as part of their TTS and SAPI systems.


Guy Fawkes(Posted 1+ years ago)

 Can someone crack into the dll w/ a dll viewer, and re-create the decls file?


Guy Fawkes(Posted 1+ years ago)

 anyone?


impersonalis(Posted 1+ years ago)

 All links are dead! Available for download only "speech synthesis"Can someone upload files, mentioned in the beginning of the theme?Sorry 4 my english)


Guy Fawkes(Posted 1+ years ago)

 .


Guy Fawkes(Posted 1+ years ago)

 Does anyone still have this zip file?


GfK(Posted 1+ years ago)

 After two years of begging, i would assume not.


Guy Fawkes(Posted 1+ years ago)

 I'm pretty sure someone does.


GfK(Posted 1+ years ago)

 Well, have fun, then.


Guy Fawkes(Posted 1+ years ago)

 Indeed I will :) [/i]