Author Topic: How to the value of a variable to play specific sounds?  (Read 6058 times)

Zerghnandus

  • Guest
How to the value of a variable to play specific sounds?
« on: August 09, 2019, 01:56:51 PM »
Hello everyone !

I'm building a custom Cold Waters profile so as i can drive the submarine 99% through voice, but i came to a hick up. VA itself cant be aware of a few values i need it be aware of like ownship bearing, depth and speed, so i have to set those values so VA knows what those values are at mission start.

After rummaging through tutorials and YouTube videos i haven't came any closer to a solution. So, my aim with this is to accomplish a few things. Namely:

1 - Set ownship depth at mission start and have VA acknowledge it;
2 - Set ownship bearing at mission start and have VA acknowledge it;
3 - Set ownship speed at mission start and have VA acknowledge it;

I noticed the game itself has a usable directory with WAVE files that it uses to voice replies so i would like to make optimal use of it for replies by VA as acknowledgements. So far i have came up with this for depth:

The command is "set depth at [1..900]"
Code: [Select]
Set Text [{cmd}] to '{CMD}'
Say, 'depth set to {TXTNUM:cmd}'

This is basically a test and it works as intended but my intention here is to use the games own WAVE files to reply and not Windows' TTS engine. The directory has voices for each number from 0 to 9 and the acknowledgements, but i cant (so far) figure out how am i going to  have VA deal with it.

This little command there replies exactly what depth i may have said, for example 854, but what i need for it to do is to play the sound files corresponding to the numbers on that cmd variable followed by the acknowledgement.

Any idea how can i go about that?

Sorry for the uber wall of text on my very first post and thanks a lot for any help !

Zergh

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #1 on: August 09, 2019, 02:26:19 PM »
The command you have only works coincidentally; You're setting the value of a variable named "cmd", because VoiceAttack strips the curly braces automatically (as they're not part of a valid token nor preceded by the "|" character).

If you want to pass the value of a token or a literal text value (which are the same thing in this context; Tokens are parsed and replaced with literal text) to tokens that support variable names and literal values, you need to wrap the value in double quotes (for text values, however not for numeric values; Check the documentation if you're unsure):
Code: [Select]
Say, 'depth set to {TXTNUM:"{CMD}"}'

To "pick apart" the number, you can use the "{TXTSUBSTR:}" token:
Code: [Select]
Set Text [depth] to '{TXTNUM:"{CMD}"}'
Start Loop : Repeat From 0 to [{EXP: {TXTLEN:depth} - 1}]
Play sound, '{VA_SOUNDS}\{TXTSUBSTR:depth:~i:1}.wav'
End Loop

You could use "{CMD}" directly here as well, but I'm assuming you're storing the depth value for later use.

The loop is a "Loop Start - Repeat a Certain Number of Times" action, with the "Range (For Loop)" option selected, and "Indexer Name" set to "~i".
For the meaning of the tilde character, have a look at the "Advanced Variable Control (Scope)" section of the manual.

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #2 on: August 09, 2019, 03:29:54 PM »
Thanks a lot for the help !

You mentioned im storing the values for later use, and yeah i am. Since the game doesn't communicate with anything outside i want to store those 3 things (Depth, Bearing and Speed) at the start of the mission for use by VA (which is also something i am not sure how to do yet since i didn't find anywhere how to set variables for use on the profile.

I was used to working with GlovePIE and it allows me to set the variables at the very start of the script so im struggling with the way VA works.

Now, on to your script, the play sound part. The game names the sound files as "zero.wav","one.wave","two.wav" and so on, so how i would go about having it play the value set to that variable? (I had quite a bit of programming experience back on the PC XT days but im very rusty and getting back to it with glove pie and now VA so i may seem quite lost sometimes.

I'm still watching tutorial videos and looking for help round the net so as to better learn this awesome program :D

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #3 on: August 09, 2019, 03:38:55 PM »
In that case, you'll have to use conditions to trigger the appropriate sound by name,
E.G.
Code: [Select]
Start Loop : Repeat From 0 to [{EXP: {TXTLEN:depth} - 1}]
    Begin Text Compare : [{TXTSUBSTR:depth:~i:1}] Equals '0'
        Play sound, '{VA_SOUNDS}\zero.wav'
    Else If Text Compare : [{TXTSUBSTR:depth:~i:1}] Equals '1'
        Play sound, '{VA_SOUNDS}\one.wav'
    End Condition
End Loop
and so on.

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #4 on: August 09, 2019, 03:40:38 PM »
Thanks a lot again !

I will try those and report the results !

 :)

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #5 on: August 11, 2019, 07:35:31 PM »
VA is recognizing my command but its giving an error: "10:32:14 PM - Unable to resolve for loop context: [{EXP: {TXTLEN:depth} - 1}].  Exiting command."

Cant figure out whats wrong. It recognizes my command when i say "set depth at 12" but it throws that error ...  :-\

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #6 on: August 11, 2019, 07:39:39 PM »
What does your full command look like?

Right-click the action list, choose "Copy All as Text", and paste the results into a code block here (click the "#" button to add them into your post automatically).


Did you add the action from the initial example?
Code: [Select]
Set Text [depth] to '{TXTNUM:"{CMD}"}'

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #7 on: August 11, 2019, 07:53:13 PM »
Here it is:

Code: [Select]
Set Text [depth] to '{TXTNUM:"{CMD}"}'
Start Loop : Repeat From 0 to [[{EXP: {TXTLEN:depth} - 1}]]
    Begin Text Compare : [[{TXTSUBSTR:depth:~i:1}]] Equals '0'
        Play sound, '{VA_SOUNDS}\ColdWatersVoices\dive officer\zero.wav'  (and wait until it completes)
    Else If Text Compare : [[{TXTSUBSTR:depth:~i:1}]] Equals '1'
        Play sound, '{VA_SOUNDS}\ColdWatersVoices\dive officer\one.wav'  (and wait until it completes)
    Else If Text Compare : [[{TXTSUBSTR:depth:~i:1}]] Equals '2'
        Play sound, '{VA_SOUNDS}\ColdWatersVoices\dive officer\two.wav'  (and wait until it completes)
    End Condition
End Loop

Im still edditing it adding each number and testing ...

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #8 on: August 11, 2019, 08:13:26 PM »
Looks like you copied the square brackets along with the tokens. Compare what you have to the examples.

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #9 on: August 11, 2019, 08:27:48 PM »
I removed the extra brackets and now it works but it repeats the first number 3 times in a row. I say "set depth at 12" and it repeats the number one 3 times.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #10 on: August 11, 2019, 08:31:41 PM »
That indicates "~i" isn't getting set. Did you configure the loop action correctly?

The loop is a "Loop Start - Repeat a Certain Number of Times" action, with the "Range (For Loop)" option selected, and "Indexer Name" set to "~i".

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #11 on: August 11, 2019, 09:06:05 PM »
That was the problem ! I'm not used to creating these complicated commands so those pop ups for creating them can be confusing !

Now it works as expected but the response is sluggish when it speaks the reply. Is that because of the loop itself?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #12 on: August 11, 2019, 09:12:59 PM »
Sluggish how? The loop should run faster than you can perceive.

Do you have the "Audio Output Type" option on the "Audio" tab of the VoiceAttack options window set to "Integrated Components"?

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #13 on: August 11, 2019, 09:14:19 PM »
Its set to "Windows Media Components"

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #14 on: August 11, 2019, 09:15:17 PM »
I'd recommend setting it to "Integrated Components", even if it doesn't solve this specific issue for you.

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #15 on: August 11, 2019, 09:24:23 PM »
I don't know what that does change but it apparently solved the problem ! Thanks a lot man !

By the way, how do i deal with prefixes and sufixes? Im trying to add more realism by directing my order at specific stations of the submarine like Helm, Dive, etc by using commands like:

I say: "Helm, right 15 degrees rudder." - In this example the station is Helm, and he command is "right 15 degrees rudder"

or

I say: " Dive, bring us 5 degrees down bubble" - In this example Dive is the station and "bring us 5 degrees down bubble" is the command

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4790
  • RTFM
Re: How to the value of a variable to play specific sounds?
« Reply #16 on: August 11, 2019, 09:26:56 PM »
You can use the "{PREFIX}" and/or "{SUFFIX}" tokens to figure out what was said without having to check the whole command string.

Though, I'd recommend using dynamic command sections instead, so you don't have to split up your commands (makes for easier maintenance, I find).


Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf, which has more information on all these things.

Zerghnandus

  • Guest
Re: How to the value of a variable to play specific sounds?
« Reply #17 on: August 11, 2019, 09:28:17 PM »
I will do that ! Thanks again man !  ;D

Shaftoe62

  • Newbie
  • *
  • Posts: 1
Re: How to the value of a variable to play specific sounds?
« Reply #18 on: April 24, 2023, 09:40:26 PM »
Haha, I admire your patience Pfeil! But this gave me exactly what I was looking for!

Thank you both!