S9ilent's Vocal Control *29/03/2015*
Moderators: Scripting / Modding Moderators, Moderators for English X Forum
-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
Hello,
You can already say
"all ships attack my target"
So I'd rather not add "in sector" to the end of that, as the generictarget isntructions have a LOT of references in them. (300 ships + 10ish classes). And by increase the complexity of the phrase, it makes it more likely to recognise the phrase incorrectly (or for it to get confused and recognise no phrases)
But if you really wanted it to do it for you one, on the re-used phrases worksheet, generictargb (On mine its cell D95)
change:
{pluralclasses}
to:
{pluralclasses} [in sector]
ORRRRR
On the sheet x3 common names, under plural classes (D116)
change:
ships
to:
ships [in sector]
As an aside, its better to use an optional, then having "ships" and "ships in sector"
You can already say
"all ships attack my target"
So I'd rather not add "in sector" to the end of that, as the generictarget isntructions have a LOT of references in them. (300 ships + 10ish classes). And by increase the complexity of the phrase, it makes it more likely to recognise the phrase incorrectly (or for it to get confused and recognise no phrases)
But if you really wanted it to do it for you one, on the re-used phrases worksheet, generictargb (On mine its cell D95)
change:
{pluralclasses}
to:
{pluralclasses} [in sector]
ORRRRR
On the sheet x3 common names, under plural classes (D116)
change:
ships
to:
ships [in sector]
As an aside, its better to use an optional, then having "ships" and "ships in sector"
-
- Posts: 40
- Joined: Sun, 2. Mar 08, 07:28
-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
*grumble grumble*
Doing that would require quite a bit of work for what you'll be getting out of it. Well... some work.. well.. I'd have to make a new command and script. (as opposed to modifying an existing one)
As in X3, find station and find ship are two separate commands, and the only neatest way to do so would be to just create a new command and script. (As opposed to adding multiple else if's to existing commands, correcting the array positions, then re-testing etcetera etcetera. There are some 20 odd scripts just to get those basic commands to work
)
Whilst generic station instructions would give SVC more versatility (especially out side of combat orientated tasks).. to be honest.. I really can't be bothered at the moment... cos like... 2? people use this program. Although, your comments have been noted, and its been appended to the SVC -todo list
(Current I'm working on my Station Financial Manager script, that has a whole 4 people using it. Its all about the numbers!)
Doing that would require quite a bit of work for what you'll be getting out of it. Well... some work.. well.. I'd have to make a new command and script. (as opposed to modifying an existing one)
As in X3, find station and find ship are two separate commands, and the only neatest way to do so would be to just create a new command and script. (As opposed to adding multiple else if's to existing commands, correcting the array positions, then re-testing etcetera etcetera. There are some 20 odd scripts just to get those basic commands to work

Whilst generic station instructions would give SVC more versatility (especially out side of combat orientated tasks).. to be honest.. I really can't be bothered at the moment... cos like... 2? people use this program. Although, your comments have been noted, and its been appended to the SVC -todo list
(Current I'm working on my Station Financial Manager script, that has a whole 4 people using it. Its all about the numbers!)
-
- Posts: 40
- Joined: Sun, 2. Mar 08, 07:28
-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
-
- Posts: 40
- Joined: Sun, 2. Mar 08, 07:28
kk thx, just needed to confirm that, alread added a new computer name, I'll be going through that now, or tomorow, sence I'm so tired my vision is begining to blur and I do belive I misunderstood that line, I thought ships meant all ships owned, and not all ships in secor, stupid misunderstanding there
-
- Posts: 269
- Joined: Sat, 20. May 06, 14:55
Hi s9ilent, I may have figured out a way to emulate keystrokes! I now have a small .exe file that does two things:
First it waits until the window called "X3TC" is active and then it opens the sector map by pressing "."
Now there are two things, can you execute a .exe from VB (I think you can, but I don't know any VB)? And will the "focus" stay on TC or will it go to the .exe?
I've uploaded the file here:
http://www.jvportfolio.net.tc/ADAMS/open_sectormap.exe
Just open a save in TC and go to a screen so that if you press "." the sector map will open. Now Alt+Tab out of TC and run the open_sectormap.exe (it might seem as if it does nothing), now open TC again and it should open the sector map nearly instantly.
I hope we can make this work
First it waits until the window called "X3TC" is active and then it opens the sector map by pressing "."
Now there are two things, can you execute a .exe from VB (I think you can, but I don't know any VB)? And will the "focus" stay on TC or will it go to the .exe?
I've uploaded the file here:
http://www.jvportfolio.net.tc/ADAMS/open_sectormap.exe
Just open a save in TC and go to a screen so that if you press "." the sector map will open. Now Alt+Tab out of TC and run the open_sectormap.exe (it might seem as if it does nothing), now open TC again and it should open the sector map nearly instantly.
I hope we can make this work

-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
1. I'm fair sure you can call other exe's from VB, although I will have to read up on it.
2. I'm not to sure which one will be the active window any more.
3. The link is down
4.
Good work, I tried very hard to make a keyboard hook but no matter what I did it wouldn't interface with non-windows stuff. How did you do it?
2. I'm not to sure which one will be the active window any more.
3. The link is down
4.

-
- Posts: 269
- Joined: Sat, 20. May 06, 14:55

http://www.autoitscript.com/autoit3/index.shtml
It's some sort of script language that can emulate keystrokes and do lots of other stuff. Basically you write a script that you can compile into a executable.
There are lots of useful examples in the download and I believe there is also plenty of documentation (not that I looked at or something


Now I don't know if those executables can accept any parameters or anything, but other wise we'll just have lot's of small ones I guess. Anyway I'm glad I could help you, it brings SVC one step closer to perfection


Edit: More good news, I was just looking through the documentation on all the commands and stuff and guess what.... You can make it read text files! So SVC might not have to be modified at all, but we can make it better if we do. Giving the ability to add your own hotkeys to SVC and stuff like that

Edit2: I now see we can also make this program run other .exe files, so we can make this start SVC if it can't be done the other way around.
Edit3: Now some bad news, SVC doesn't seem to be updating the 't' file. The debug version picks up the commands I say flawlessly, but when I look at the 't' file it doesn't change. I had it open in IE and just hit refresh very fast while saying commands and it didn't change at all.
I'm going to download it again to see if that fixes it (I have like five different versions on my desktop now), so I hope that'll fix it.
Edit4: False alarm

-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
The debug version updates the tfile every 10 seconds, where as the normal one does it every 1 second.
If you want it to update instantly, just press stop (it will update the tfile to the last "tick"). I used it for testing mostly, so I needed it to be longer then 1 second.
(But of course, using it in game will actually result in the command being run 10 times, as the game reads it every 1 second)
The program only "recognises" when it picks up an entire phrase. The text spam of "Hyp: xxxx" are its hypothesise of what it thinks your trying to say, and doesn't actually result in the tfile changing at all.
I still can't access the link
I can't even get to here: http://www.jvportfolio.net.tc/
I can see the other programs link thou, Ill read it up later
If you want it to update instantly, just press stop (it will update the tfile to the last "tick"). I used it for testing mostly, so I needed it to be longer then 1 second.
(But of course, using it in game will actually result in the command being run 10 times, as the game reads it every 1 second)
The program only "recognises" when it picks up an entire phrase. The text spam of "Hyp: xxxx" are its hypothesise of what it thinks your trying to say, and doesn't actually result in the tfile changing at all.

I can't even get to here: http://www.jvportfolio.net.tc/
I can see the other programs link thou, Ill read it up later
-
- Posts: 269
- Joined: Sat, 20. May 06, 14:55
Well that's really odd that you can't reach it. I can reach it just fine (tried it on different computers). Anyway I'm working on the SVC keystroke part as I'm typing this, I think I can have a pre-Beta ready this evening/tomorrow morning.
Edit: I have only one other idea left, besides uploading it to another site. Please, try this link:
http://jvportfolio.oxyrack.com/ADAMS/open_sectormap.exe
Edit2: I think it's working good now
http://jvportfolio.oxyrack.com/ADAMS/s9 ... trokes.exe
You need to place the that file (s9ilent.keystrokes.exe) in the same folder as SVC is in. To run it, you first have to start SVC (Debug or normal, doesn't matter which) and then the 's9ilent.keystrokes.exe'. You should be able to see a small icon on your tray that shows 's9ilent.keystrokes.exe' if you hover your mouse over it. To close it, you simply close SVC. Note: The reaction time can be quite slow, so be patient after you said a command
If that's all up and running you still need some command phrases
You can easily make your own if you follow the syntax I'll explain now.
As example I'll make a phrase to open the sector map. The phrase looks like this in the excel file:
That's all you need to have to make your phrase. No optionals or anything, just a top level phrase.
You might notice the name is a bit strange, especially at the end. That is because between the 2 |'s are the key(s) that need to be pressed to open the sector map (a period in this case). So if you want to make a phrase to open the universe map the phrase name should contain: |,|
It shouldn't matter where you put that part in the name of your phrase. It's very important to have 2 |'s, it won't work otherwise!
I hope it's clear enough and feel free to ask questions.
Edit: I have only one other idea left, besides uploading it to another site. Please, try this link:
http://jvportfolio.oxyrack.com/ADAMS/open_sectormap.exe
Edit2: I think it's working good now

http://jvportfolio.oxyrack.com/ADAMS/s9 ... trokes.exe
You need to place the that file (s9ilent.keystrokes.exe) in the same folder as SVC is in. To run it, you first have to start SVC (Debug or normal, doesn't matter which) and then the 's9ilent.keystrokes.exe'. You should be able to see a small icon on your tray that shows 's9ilent.keystrokes.exe' if you hover your mouse over it. To close it, you simply close SVC. Note: The reaction time can be quite slow, so be patient after you said a command

If that's all up and running you still need some command phrases

You can easily make your own if you follow the syntax I'll explain now.
As example I'll make a phrase to open the sector map. The phrase looks like this in the excel file:
Code: Select all
Phrase Name: open.sector.map|.|
Phrase: Open sector [map]
You might notice the name is a bit strange, especially at the end. That is because between the 2 |'s are the key(s) that need to be pressed to open the sector map (a period in this case). So if you want to make a phrase to open the universe map the phrase name should contain: |,|
It shouldn't matter where you put that part in the name of your phrase. It's very important to have 2 |'s, it won't work otherwise!
I hope it's clear enough and feel free to ask questions.
-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
Your Edit1: link works
I've got the program in the folder
I started my game, loaded it, I'm sitting in space just normally. (where you can open up the maps by pressing , or .
And then i alt-tabbed out, started the program (I see it in the sys tray)
alt tabed back in
Butt, it doesn't do anything.
(But the program kills it self when i alt tab back out, so I assume that it tried to run once, then quits after the first attempt)
*edit* wait... its working now.. (WOOoOOooOooo).. How bizarre thou...
*re edit* It some times works, I suspect because it sends the . to early when my computer is still switching programs. (which won't really be a problem when completed, as it would be called silently or something)
I've got the program in the folder
I started my game, loaded it, I'm sitting in space just normally. (where you can open up the maps by pressing , or .
And then i alt-tabbed out, started the program (I see it in the sys tray)
alt tabed back in
Butt, it doesn't do anything.
(But the program kills it self when i alt tab back out, so I assume that it tried to run once, then quits after the first attempt)
*edit* wait... its working now.. (WOOoOOooOooo).. How bizarre thou...
*re edit* It some times works, I suspect because it sends the . to early when my computer is still switching programs. (which won't really be a problem when completed, as it would be called silently or something)
-
- Posts: 269
- Joined: Sat, 20. May 06, 14:55
I take it that's with that first thing I posted (open_sectormap.exe)? Anyway that's good to know, I could build in a small delay after you switch back to TC.
I'd also like you to try the second one I posted (s9ilent.keystrokes.exe), you need to do all the stuff I typed below it to make it work. It can read the .xml files dynamically (the X3TC.xml in the SVC folder and the 7742-L044.xml) and then it compares the commands in 7742-L044.xml with the ones in X3TC.xml and if they match the keys are pressed. There are also some other arguments before the keys are pressed, but those are just to make sure that the command you said requires the computer to press keys.
The only problem I see now is the reaction time. My program checks every three seconds because that's about the refresh rate for SVC, right? If I make it look faster it'll run the phrase command multiple times. Maybe you could make SVC write keyboard commands to a different file that gets refreshed every second or so?
I'd also like you to try the second one I posted (s9ilent.keystrokes.exe), you need to do all the stuff I typed below it to make it work. It can read the .xml files dynamically (the X3TC.xml in the SVC folder and the 7742-L044.xml) and then it compares the commands in 7742-L044.xml with the ones in X3TC.xml and if they match the keys are pressed. There are also some other arguments before the keys are pressed, but those are just to make sure that the command you said requires the computer to press keys.
The only problem I see now is the reaction time. My program checks every three seconds because that's about the refresh rate for SVC, right? If I make it look faster it'll run the phrase command multiple times. Maybe you could make SVC write keyboard commands to a different file that gets refreshed every second or so?
-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
The SVC proper refreshes every 1 second (as of... I don't know... It used to be 3 thou, since v3.0 I think)
I don't have enough time to look at it properly today, but last time I looked at the script thingys website, it mentioned use of .com's and ... erhh... the other thing.. plugin doo hickeys.
Now I'm not to sure if it means it can interface it's .coms with other languages, or if other languages can interface the script's .com's. But in either case I think a consolidated program is preferably to running twoish background programs.
(The voice recognition it self -the windows components of it- are .com's so hopefully it should be do-able in a slightly cleaner format. Tbh I'm already a little un-happy at having to continuously spit out/read a text file, the 0-1 second lag is gets annoying, and that's on top of the failed recognitions)
I don't have enough time to look at it properly today, but last time I looked at the script thingys website, it mentioned use of .com's and ... erhh... the other thing.. plugin doo hickeys.
Now I'm not to sure if it means it can interface it's .coms with other languages, or if other languages can interface the script's .com's. But in either case I think a consolidated program is preferably to running twoish background programs.
(The voice recognition it self -the windows components of it- are .com's so hopefully it should be do-able in a slightly cleaner format. Tbh I'm already a little un-happy at having to continuously spit out/read a text file, the 0-1 second lag is gets annoying, and that's on top of the failed recognitions)
-
- Posts: 269
- Joined: Sat, 20. May 06, 14:55
Yeah, I also don't really like the idea of having multiple programs running in the background, but for testing to see what it can do it's fine. Also CPU load wise I don't think there is any real problem, I never see more then 1% CPU usage with SVC and the keystroke detection on. Then again I have a quad core so usage on a single processor might be 4x higher.
Well I don't know if you can make .com files with it, but I'll have look. I also don't have much time today so I think it'll be tomorrow morning before I can look at it.
Edit: I just got a very good idea, if we can make SVC and the keystroke thing work together we can make SVC press a hotkey for X3TC. So when SVC recognizes a command it presses a hotkey to launch a script in X3 that reads the 7742-L044.xml file. No more loops with 1 second delays and no more delays before a command phrase gets executed.
On .com files, as far as I understand AutoIt can execute/read them, but you can't make AutoIt scripts into .com files. I'm not sure about it though, I'll have to do some more searching for that.
Edit2: I have some good news and perhaps some bad. The good news is that speech recognition can be done in AutoIt (I've found topics on the forums and sample codes and stuff), the bad news is that you probably have to convert the code you have written so far (If we want everything to be just 1 .exe). I know to little about writing speech recognition code and VB to judge how much work that would be, so you have to see for your self. For more info on speech recognition in AutoIt, just use the search on their forums and type in "speech recognition", typing in voice recognition won't yield any results
Edit3: Ok, I think I know a little how it works now. Apparently SAPI produces all sorts of events to hook on to, AutoIt can also hook on to those events. Also, it doesn't seem to be too hard to convert VB to AutoIt. I can help you, but you'll have to give the code to me... You can also do it yourself if your not so keen on sharing your code or if it's really complicated
:roll:
Well I don't know if you can make .com files with it, but I'll have look. I also don't have much time today so I think it'll be tomorrow morning before I can look at it.
Edit: I just got a very good idea, if we can make SVC and the keystroke thing work together we can make SVC press a hotkey for X3TC. So when SVC recognizes a command it presses a hotkey to launch a script in X3 that reads the 7742-L044.xml file. No more loops with 1 second delays and no more delays before a command phrase gets executed.
On .com files, as far as I understand AutoIt can execute/read them, but you can't make AutoIt scripts into .com files. I'm not sure about it though, I'll have to do some more searching for that.
Edit2: I have some good news and perhaps some bad. The good news is that speech recognition can be done in AutoIt (I've found topics on the forums and sample codes and stuff), the bad news is that you probably have to convert the code you have written so far (If we want everything to be just 1 .exe). I know to little about writing speech recognition code and VB to judge how much work that would be, so you have to see for your self. For more info on speech recognition in AutoIt, just use the search on their forums and type in "speech recognition", typing in voice recognition won't yield any results

Edit3: Ok, I think I know a little how it works now. Apparently SAPI produces all sorts of events to hook on to, AutoIt can also hook on to those events. Also, it doesn't seem to be too hard to convert VB to AutoIt. I can help you, but you'll have to give the code to me... You can also do it yourself if your not so keen on sharing your code or if it's really complicated

-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
Ok, I've finally had a chance to look at AutoIt. And well
not happy.
It certainly does keyboard hooks, and can do all the features that I'm using in VB. Howeverrrr... I misinterpretted the COM -ness of it.
I thought it meant AutoIt had a COM that I could load with vb (so I could consolidate in VB), but actually AutoIt can load coms (so the only way to consolidate is to make it entirely in AutoIt).

*sigh* guess its time to learn a new scripting language?
w.r.t Your edit 1 I thought about that idea but X3 it self has limits to how quickly you type (especially when lagging). For some reason... X3 doesn't read on key down.. but on key holds...
And give how some voice commands can return quite a few variables, this severely limits the input-ability of just using hotkeys. (As there are only so many keys on the keyboard, and using multiple keys will be even messier)
w.r.t Edit 2. Yep
Refer to above *sigh*
w.r.t Edit 3. Hm.... I'm more then happy to give the code. T.b.h I've lost lots of the interest in this project (as it seems to be only you and me doing it
). Either people can't get it working on their windows side or... actually yeh that's about it.. no interest/can't get windows working.
Code is as follows:
1. The excel generates the XML grammar file. Its a fair basic XML. To see the code that I used to generate that, just open up the VBA editor (alt f-11).
To be honest.. there is probably more code in that dam excel sheet then in the XML file it self.
There is one more tag which you can use that I haven't, and that is for dictation. (eg like how you can put ... in a line, you can put I think its a * or something, to allow for free speech in a phrase).
As for the actual programs code, ill put it in the next post for clarity (and Ill try to explain it)
*edit* sorry for the slow reply, didn't actually know you posted
, I get a fair few emails a day from the auto-forum-post thing

It certainly does keyboard hooks, and can do all the features that I'm using in VB. Howeverrrr... I misinterpretted the COM -ness of it.
I thought it meant AutoIt had a COM that I could load with vb (so I could consolidate in VB), but actually AutoIt can load coms (so the only way to consolidate is to make it entirely in AutoIt).

*sigh* guess its time to learn a new scripting language?
w.r.t Your edit 1 I thought about that idea but X3 it self has limits to how quickly you type (especially when lagging). For some reason... X3 doesn't read on key down.. but on key holds...
And give how some voice commands can return quite a few variables, this severely limits the input-ability of just using hotkeys. (As there are only so many keys on the keyboard, and using multiple keys will be even messier)
w.r.t Edit 2. Yep

w.r.t Edit 3. Hm.... I'm more then happy to give the code. T.b.h I've lost lots of the interest in this project (as it seems to be only you and me doing it

Code is as follows:
1. The excel generates the XML grammar file. Its a fair basic XML. To see the code that I used to generate that, just open up the VBA editor (alt f-11).
To be honest.. there is probably more code in that dam excel sheet then in the XML file it self.
There is one more tag which you can use that I haven't, and that is for dictation. (eg like how you can put ... in a line, you can put I think its a * or something, to allow for free speech in a phrase).
As for the actual programs code, ill put it in the next post for clarity (and Ill try to explain it)
*edit* sorry for the slow reply, didn't actually know you posted

Last edited by s9ilent on Thu, 12. Feb 09, 01:25, edited 1 time in total.
-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
Tip, put it in VB 2008 if you want to read the code, it formats it all nicely, puts in colour and has tree view for all the subs
Note to all, Please ask for permission before using this code
@jeff, feel free to use the code for what ever.
Note to all, Please ask for permission before using this code
@jeff, feel free to use the code for what ever.
Code: Select all
Option Explicit On
Public Class Form1
Inherits System.Windows.Forms.Form
'=============================================================================
'
' This RecoVB App sample demonstrates most of the SR functionalities
' supported in SAPI 5.1. The main object used here for the RecoContext is RC.
'
' Copyright @ 2001 Microsoft Corporation All Rights Reserved.
'
'=============================================================================
Public WithEvents RC As SpeechLib.SpSharedRecoContext 'The main shared Recognizer Context
Public Grammar As SpeechLib.ISpeechRecoGrammar 'Command and Control interface
Dim fRecoEnabled As Boolean 'Is recognition enabled
Dim fGrammarLoaded As Boolean 'Is a grammar loaded
'Dim RecoResult As SpeechLib.ISpeechRecoResult 'Recognition result interface
Dim recocount As Long
Dim path As String
Dim oldtfile As New ArrayList()
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
Dim oWrite As System.IO.StreamWriter
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
On Error GoTo Err_SAPILoad
fRecoEnabled = False
fGrammarLoaded = False
path = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\EGOSOFT\X3TC", "INSTALL_DIR", "No dir")
If path = "No dir" Then
path = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Valve\Steam", "SteamPath", "Failed")
If Len(path) > 6 Then
path = path & "steamapps\common\x3 terran conflict"
path = path.Replace("/", "\")
Else
If IO.File.Exists(CurDir() & "\config.cfg") = True Then
oRead = oFile.OpenText(CurDir() & "\config.cfg")
If oRead.Peek <> -1 Then path = oRead.ReadLine()
oRead.Close()
If IO.File.Exists(path & "\X3TC.exe") = True Then
TextBox1.SelectedText += "Using saved path: " & path & vbCrLf
End If
Else
TextBox1.SelectedText += "Can not find path, please type in the path" & vbCrLf
End If
End If
TextBox1.SelectedText += "Steam Dir: " & path & vbCrLf
Else
TextBox1.SelectedText += "Game Dir: " & path & vbCrLf
End If
If IO.File.Exists(path & "\X3TC.exe") = False Then TextBox1.SelectedText += _
"Please verify that the game directory is correct" & vbCrLf
TextBox2.Text = path
'Interval is in miliseconds apparently
Timer1.Interval = 3000
' Create the Shared Reco Context by default
RC = New SpeechLib.SpSharedRecoContext
LoadGrammarObj()
LoadDefaultCnCGrammar()
On Error GoTo Err_SAPILoad
Exit Sub
Err_SAPILoad:
MsgBox("Error loading SAPI objects! Please make sure SAPI5.1 is correctly installed.", MsgBoxStyle.Critical)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If IO.File.Exists(path & "\t\7742-L044.xml") = True Then
Resetfile()
End If
End Sub
Private Sub LoadGrammarObj()
Grammar = RC.CreateGrammar(1)
End Sub
Private Sub LoadDefaultCnCGrammar()
TextBox1.SelectedText += "Reloading Grammar, "
On Error Resume Next
Grammar.CmdLoadFromFile(CurDir() & "\x3tc.xml", SpeechLib.SpeechLoadOption.SLODynamic)
If Err.Number Then
On Error GoTo Err_CFGLoad
Grammar.CmdLoadFromFile("C:\x3tc.xml", SpeechLib.SpeechLoadOption.SLODynamic)
fGrammarLoaded = True
Grammar.CmdSetRuleIdState(0, SpeechLib.SpeechRuleState.SGDSInactive)
TextBox1.SelectedText += "Root Grammar Loaded" & vbCrLf
Exit Sub
End If
On Error GoTo Err_CFGLoad
Grammar.CmdSetRuleIdState(0, SpeechLib.SpeechRuleState.SGDSInactive)
TextBox1.SelectedText += "Grammar Loaded" & vbCrLf
fGrammarLoaded = True
TextBox1.SelectedText += vbCrLf
Exit Sub
Err_CFGLoad:
fGrammarLoaded = False
TextBox1.SelectedText += "Failed Loading Grammar" & vbCrLf
Exit Sub
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' First make sure a valid .xml file is loaded if the user is selecting C&C
If fGrammarLoaded = True Then
If Not fRecoEnabled Then
'If recognition is currently not enabled, enable it.
path = TextBox2.Text
If System.IO.Directory.Exists(path & "\scripts") = False Then GoTo ErrorPath
On Error Resume Next
Dim sfiles() As String = Directory.GetFiles(CurDir() & "\scripts")
For i As Integer = 0 To UBound(sfiles)
File.Copy(sfiles(i), path & "\scripts\" & System.IO.Path.GetFileName(sfiles(i)), True)
Next
Dim svcfiles() = Directory.GetFiles(CurDir() & "\svcscripts")
For i As Integer = 0 To UBound(svcfiles)
File.Copy(svcfiles(i), path & "\scripts\" & System.IO.Path.GetFileName(svcfiles(i)), True)
Next
If Err.Number Then MsgBox("Error copying X3TC Script files", MsgBoxStyle.Critical)
On Error GoTo ErrorHandle
File.Copy(CurDir() & "\7743-L044.xml", path & "\t\7743-L044.xml", True)
If Err.Number Then MsgBox("7743-L044.xml not found", MsgBoxStyle.Critical)
On Error GoTo ErrorHandle
LoadDefaultCnCGrammar()
On Error GoTo ErrorHandle
Grammar.CmdSetRuleIdState(0, SpeechLib.SpeechRuleState.SGDSActive)
fRecoEnabled = True
Timer1.Enabled = True
Button1.Text = "&Stop Recognition"
TextBox2.ReadOnly = True
Else
'If recognition is currently enabled, disable it.
Grammar.CmdSetRuleIdState(0, SpeechLib.SpeechRuleState.SGDSInactive)
fRecoEnabled = False
Timer1.Enabled = False
Button1.Text = "&Start Recognition"
TextBox2.ReadOnly = False
End If
End If
Exit Sub
ErrorHandle:
MsgBox("Failed to activate the grammar. It is possible that your audio device is used by other application.", MsgBoxStyle.OkOnly)
Exit Sub
ErrorPath:
MsgBox("Unable to locate the X3 Terran Conflict\scripts folder", MsgBoxStyle.OkOnly)
End Sub
Private Sub RC_Recognition(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult) Handles RC.Recognition
recocount = recocount + 1
Dim theFirstElement As Integer
Dim theNumberOfElements As Integer
Dim i As Integer
Dim j As Integer
Dim tid As Long
Dim count2 As Long
On Error Resume Next
'Add my stuff to the arraylist
tid = recocount * 50
oldtfile.Add(Chr(9) & Chr(9) & "<t id=""" & tid & """>" & Result.PhraseInfo.Rule.Name & "</t>")
'Add a placeholder for the total count of items
tid = tid + 1
oldtfile.Add("")
count2 = oldtfile.Count - 1
tid = tid + 1
oldtfile.Add(Chr(9) & Chr(9) & "<t id=""" & tid & """>" & Result.PhraseInfo.Properties.Count & "</t>")
For i = 0 To Result.PhraseInfo.Properties.Count - 1
tid = tid + 1
oldtfile.Add(Chr(9) & Chr(9) & "<t id=""" & tid & """>" & Result.PhraseInfo.Properties.Item(i).Name & "</t>")
tid = tid + 1
oldtfile.Add(Chr(9) & Chr(9) & "<t id=""" & tid & """>" & Result.PhraseInfo.Properties.Item(i).Value & "</t>")
theFirstElement = Result.PhraseInfo.Properties.Item(i).FirstElement
theNumberOfElements = Result.PhraseInfo.Properties.Item(i).NumberOfElements
For j = 0 To theNumberOfElements - 1
tid = tid + 1
oldtfile.Add(Chr(9) & Chr(9) & "<t id=""" & tid & """>" & Result.PhraseInfo.Elements(theFirstElement + j).DisplayText & "</t>")
Next
Next
'Now apply the total count of items
oldtfile(count2) = Chr(9) & Chr(9) & "<t id=""" & recocount * 50 + 1 & """>" & tid - recocount * 50 & "</t>"
End Sub
Private Sub Resetfile()
oWrite = oFile.CreateText(path & "\t\7742-L044.xml")
oWrite.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")
oWrite.WriteLine("<language id=""44"">")
oWrite.WriteLine(Chr(9) & "<page id=""7742"" title=""Voice Control"" descr="""">")
oWrite.WriteLine(Chr(9) & Chr(9) & "<t id=""0"">0</t>")
oWrite.WriteLine(Chr(9) & "</page>")
oWrite.WriteLine("</language>")
oWrite.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Tickactual()
End Sub
Private Sub Tickactual()
oWrite = oFile.CreateText(path & "\t\7742-L044.xml")
oWrite.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")
oWrite.WriteLine("<language id=""44"">")
oWrite.WriteLine(Chr(9) & "<page id=""7742"" title=""Voice Control"" descr="""">")
oWrite.WriteLine(Chr(9) & Chr(9) & "<t id=""0"">" & recocount & "</t>")
For i = 0 To oldtfile.Count - 1
oWrite.WriteLine(oldtfile.Item(i))
Next
oWrite.WriteLine(Chr(9) & "</page>")
oWrite.WriteLine("</language>")
oWrite.Close()
recocount = 0
oldtfile.Clear()
End Sub
End Class
Last edited by s9ilent on Thu, 12. Feb 09, 01:17, edited 2 times in total.
-
- Posts: 2033
- Joined: Wed, 29. Jun 05, 01:45
Ok
(This is on the SVC beta, not the debug, the debug has more junk in it + prints out all the recognition results)
First up, the form is form1
On the form there is a
label (label1), is not tweaked by the scripts, its capition is the "X3TC Path"
There there is textbox1, the big multi line text box
Textbox2, this is the path text box
Button1, the start/stop button
Oh and a timer1, Its the 1 second timer that triggers the tfiles creation
Now the code it self
There are 9 Private sub's
form1_load -Run when the program opens, loads the default path, gives an error if it can't find it. Calls the loaddefaultgrammar
form1_formclosing -calls resetfile on program close
loadgrammarobj - not to sure.. but the tutorial script had this and I never really took it out. I was worried it might have been one of those event thingies, or used by SAPI, so I never took it out. It literally only has 1 line in it.
loaddefaultcncgrammar- Loads the grammar file from the relevent directory, on failure tries root, if still fails gives an error message
button1_click - basically turns the thing on/off. (in truth its more like on and pause, then off, as the tfile is still there and being red by your game if left running. On closing the app resets the tfile)
rc_recognition -This is the event that happens when sapi recognizes something. It adds all the data to an array. (The data added is the string to be put into the tfile)
resetfile- resets the tfile, such that it is blank (tid'0' "0")
timer1_tick- this is run every time the timer goes off (i.e every second), it calls tickactual
tickactual- This gets the array of all the string tfile data. And creates the tfile.
Now a quick summary of how it actually works.
1. It opens, loads the grammar and directories and all of that stuff.
2a. Copies all the X3 scripts, to the x3 script folders. (N.B, including the tfile (7743) that registers phrase names with script names)
2b. On next load, X3 reads that 7743 tfile, and re-creates the phrasename-scriptname global arrays. (it overwrites the previous one)
3a. Every 1 second, it reads the array, "oldtfile" and creates the tfile from that.
3b. Every 1 second, X3TC reads that tfile, and then sends the array of return variables (which are all strings) to the associated script.
Now a quick summary of the 7743 phrase-script name tfile.
This file is created by the Excel sheet (where the input stuff is on the config work sheet)
It basically has
0 = # of total phrase/scripts
then 1 is the first script, 1001 is the first phrasename
2-1002, 3-1003, etc etc.
So if the 0th entry is 5, it loads 1-1001, up to 5-1005
Now a summary of the 7742 tfile (Where all the data is actually sent)
The 0th element again, is a counter, but for the number of phrases.
The phrases start at 50, then 100, 150 200 250 etc.
(of course its not physically possible to say that many phrases in 1 second.. but the framework is there in case you do...)
For a given slot of 50
the 50*n + 0th element is the number of total elements in this phrase block. I think at least... I can't remember if its size, or size - 1.
In either case, it tells the X3 script, how many text entries its supposed to read. It throws all those text entries into an array, then sends it off to the associated script.
And.. yeh. Thats about all that I can fill in the summary.
But wow... I haven't looked at this script in ages..
I knew that at some point I made it to an AL plugin. I had just always assumed that I had put it back to a non-al plugin.. *shrug*
Oh well.
(An AL plugin restricts you to work in seconds, but has an easily accessible on-off, but a normal script would've allowed for ms time increments, but then you would need to bind some sort of hotkey or something to be able to turn it off)
(This is on the SVC beta, not the debug, the debug has more junk in it + prints out all the recognition results)
First up, the form is form1
On the form there is a
label (label1), is not tweaked by the scripts, its capition is the "X3TC Path"
There there is textbox1, the big multi line text box
Textbox2, this is the path text box
Button1, the start/stop button
Oh and a timer1, Its the 1 second timer that triggers the tfiles creation
Now the code it self
There are 9 Private sub's
form1_load -Run when the program opens, loads the default path, gives an error if it can't find it. Calls the loaddefaultgrammar
form1_formclosing -calls resetfile on program close
loadgrammarobj - not to sure.. but the tutorial script had this and I never really took it out. I was worried it might have been one of those event thingies, or used by SAPI, so I never took it out. It literally only has 1 line in it.
loaddefaultcncgrammar- Loads the grammar file from the relevent directory, on failure tries root, if still fails gives an error message
button1_click - basically turns the thing on/off. (in truth its more like on and pause, then off, as the tfile is still there and being red by your game if left running. On closing the app resets the tfile)
rc_recognition -This is the event that happens when sapi recognizes something. It adds all the data to an array. (The data added is the string to be put into the tfile)
resetfile- resets the tfile, such that it is blank (tid'0' "0")
timer1_tick- this is run every time the timer goes off (i.e every second), it calls tickactual
tickactual- This gets the array of all the string tfile data. And creates the tfile.
Now a quick summary of how it actually works.
1. It opens, loads the grammar and directories and all of that stuff.
2a. Copies all the X3 scripts, to the x3 script folders. (N.B, including the tfile (7743) that registers phrase names with script names)
2b. On next load, X3 reads that 7743 tfile, and re-creates the phrasename-scriptname global arrays. (it overwrites the previous one)
3a. Every 1 second, it reads the array, "oldtfile" and creates the tfile from that.
3b. Every 1 second, X3TC reads that tfile, and then sends the array of return variables (which are all strings) to the associated script.
Now a quick summary of the 7743 phrase-script name tfile.
This file is created by the Excel sheet (where the input stuff is on the config work sheet)
It basically has
0 = # of total phrase/scripts
then 1 is the first script, 1001 is the first phrasename
2-1002, 3-1003, etc etc.
So if the 0th entry is 5, it loads 1-1001, up to 5-1005
Now a summary of the 7742 tfile (Where all the data is actually sent)
The 0th element again, is a counter, but for the number of phrases.
The phrases start at 50, then 100, 150 200 250 etc.
(of course its not physically possible to say that many phrases in 1 second.. but the framework is there in case you do...)
For a given slot of 50
the 50*n + 0th element is the number of total elements in this phrase block. I think at least... I can't remember if its size, or size - 1.
In either case, it tells the X3 script, how many text entries its supposed to read. It throws all those text entries into an array, then sends it off to the associated script.
And.. yeh. Thats about all that I can fill in the summary.
But wow... I haven't looked at this script in ages..
I knew that at some point I made it to an AL plugin. I had just always assumed that I had put it back to a non-al plugin.. *shrug*
Oh well.
(An AL plugin restricts you to work in seconds, but has an easily accessible on-off, but a normal script would've allowed for ms time increments, but then you would need to bind some sort of hotkey or something to be able to turn it off)
-
- Posts: 269
- Joined: Sat, 20. May 06, 14:55
wow thanks s9ilent
I'll have a more thorough look at it later today. Thanks, thanks, thanks 
Yeah it's to bad it's only us that are really doing something with it, though some reactions seem really enthusiastic at first they seem to be few and not really interested after they see what they need to do to set it up. Anyway, thanks man
:D


Yeah it's to bad it's only us that are really doing something with it, though some reactions seem really enthusiastic at first they seem to be few and not really interested after they see what they need to do to set it up. Anyway, thanks man

-
- Posts: 5
- Joined: Mon, 14. Nov 05, 22:45
Problem in game executing scripts.
First off, this thing looks to be prety sweet, so props on that...
I've been having some trouble getting it working though. I downloaded the latest version from here (again after i had trouble just to make sure).
I fired up the debug one, and sure enough saw the commands getting recognized properly about 85% of the time (I likely need to train better).
The problem is, nothing gets executed in the game. I tried it with both the beta and debug EXEs. I also checked the 7742-L044.xml file, and it is getting changed when I speak a new command (ie target nearest ship).
If i call plugin.svc.main manualy, it seems to issue the command (as long as I do it soon enough). The AL is turned on (and I have tried it with it off as well, with no luck).
So basicaly I am stuck here... what do I do next... I have no experience with AL scripts, so I'm not sure where to even start on that one.
--Note: For some reason it is still called al.plugin.svc in the AL menus.
On a totaly separate note, if you are still looking into the keypress stuff, I have some code around here somewhere for VB that may do what you need right from your EXE. It adds kepresses directly to the buffer, instead of trying to send them to an app. I wrote it for an industrial controls application (I'm a controls engineer) that did not like responding normaly either. If you are interested, let me know and I'll try to dig up the source.
I've been having some trouble getting it working though. I downloaded the latest version from here (again after i had trouble just to make sure).
I fired up the debug one, and sure enough saw the commands getting recognized properly about 85% of the time (I likely need to train better).
The problem is, nothing gets executed in the game. I tried it with both the beta and debug EXEs. I also checked the 7742-L044.xml file, and it is getting changed when I speak a new command (ie target nearest ship).
If i call plugin.svc.main manualy, it seems to issue the command (as long as I do it soon enough). The AL is turned on (and I have tried it with it off as well, with no luck).
So basicaly I am stuck here... what do I do next... I have no experience with AL scripts, so I'm not sure where to even start on that one.
--Note: For some reason it is still called al.plugin.svc in the AL menus.
On a totaly separate note, if you are still looking into the keypress stuff, I have some code around here somewhere for VB that may do what you need right from your EXE. It adds kepresses directly to the buffer, instead of trying to send them to an app. I wrote it for an industrial controls application (I'm a controls engineer) that did not like responding normaly either. If you are interested, let me know and I'll try to dig up the source.