Speech Synthesis icon Speech Synthesis Speak user-defined text via PC audio or EZ-B v4 speaker; configurable voices, effects and speed; uses Windows TTS; programmatically callable. Try it →
Australia
Asked
Resolved Resolved by Athena!
Speech Recognition Mic Variable

Speech Recognition Mic Variable

,

I'm using the Speech Recognition robot skill in ARC. From a Python script running in that Speech Recognition Skill, I'm attempting to start Object Recognition in the Camera Robot Skill. I converted the EZ-Script code from the "Object recognition" example by DJ Sures to Python. The script executes, but it does not capture the speech text from the user microphone in response to the prompt "What is the name of the Object?"

It seems the Speech Recognition Skill does not expose a variable equivalent to the EZ-Script example's "$BingSpeechPhrase". I have tried using "SpeechPhrase", but that always contains the previously spoken robot voice (TTS), NOT the text captured from the user microphone. Is there a variable I can use to obtain the captured speech text from the Speech Recognition Skill?

Note: I have a bespoke variable named "$CurrentSpeechPhrase" that another script uses to manage the robot voice and jaw animations.

My Python script (converted from EZ-Script) is shown below:

import time

# Ask for the object name
setVar("$CurrentSpeechPhrase", "what is the name of the new object")
setVar("$IsSaying", 1)
while getVar("$IsSaying") == 1:
    time.sleep(3.0)

# Reset speech variable and start listening
setVar("$SpeechPhrase", "")
controlCommand("Speech Recognition", "PauseOff")
time.sleep(0.25)
setVar("$SpeechPhrase","?????????")  #

# Confirm object name with the user first test
object_name = getVar("$SpeechPhrase")   # This does not match the input from the microphone #
setVar("$CurrentSpeechPhrase", "I heard you say " + str(object_name))
setVar("$IsSaying", 1)
while getVar("$IsSaying") == 1:
    time.sleep(0.1)

# Wait for Bing Speech to get a response
while getVar("$SpeechPhrase") == "":
    time.sleep(0.25)

# Confirm object name with the user
object_name = getVar("$SpeechPhrase")
setVar("$CurrentSpeechPhrase", "Excellent. Let me know when you are ready to teach me what the " + str(object_name) + " is.")
setVar("$IsSaying", 1)
while getVar("$IsSaying") == 1:
    time.sleep(0.1)

# Wait for 'OK' or 'Cancel' voice confirmation (Timeout: 60 seconds)
# Note: waitForSpeech is a native ARC global function
resp = Audio.waitForSpeech(60, "OK", "Cancel")
if resp != "OK":
    setVar("$CurrentSpeechPhrase", "ok, I will not learn the " + str(object_name))
    setVar("$IsSaying", 1)
    # Stop script execution
    exit()

# Disable current tracking to prepare for training
controlCommand("Camera", "CameraObjectTrackingDisable")

# Train the new object
controlCommand("Train Vision Object By Script", "Learn", str(object_name))
time.sleep(1.0)

# Wait while the camera is actively learning
while getVar("$CameraIsLearning") == True:
    time.sleep(0.25)

# Success confirmation
setVar("$CurrentSpeechPhrase", "Great, I know what a " + str(object_name) + " is.")
setVar("$IsSaying", 1)
while getVar("$IsSaying") == 1:
    time.sleep(0.1)

# Re-enable regular camera tracking
controlCommand("Camera", "CameraObjectTracking")

Thanks.



Related Hardware (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4/2 robot controller: dual Cortex ARM, Wi-Fi, audio/video, 24 servo/digital ports, I2C/UART, camera and Synthiam ARC control for custom robots
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skills (view all robot skills)
Train camera vision objects via controlcommand(), attach camera, start learning, monitor progress, and return object name for scripts.
Windows Speech Recognition skill: detect custom phrases via PC mic, trigger configurable scripts/actions with adjustable confidence.

ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Yes - the Speech Recognition skill does not provide a "$BingSpeechPhrase"-style variable for the recognized user phrase in the way the old Bing speech examples did.

What you want is usually the last recognized phrase variable exposed by the Speech Recognition skill itself, which in ARC is typically:

  • $SpeechPhrase = the last recognized phrase
  • $SpeechConfidence = confidence of the last recognition

However, in your case the reason you’re seeing the robot’s TTS text instead of the user’s microphone input is likely because your own custom variable ($CurrentSpeechPhrase) and/or the speech/jaw logic is updating $SpeechPhrase or your script is reading it at the wrong time.

Important distinction

  • Speech Recognition skill listens to the microphone
  • Audio.say... / TTS is the robot speaking
  • Those are separate paths

So if "$SpeechPhrase" is showing the spoken robot text, then that variable is likely being used by another script as a shared "current phrase" variable, not the Speech Recognition skill’s recognized input.


Better approach

Use the Speech Recognition skill’s built-in recognized phrase variable from that control, not your custom phrase variable.

If you’re using the Speech Recognition robot skill, check its settings:

  • Open the skill’s kebab menu (three lines in the top-right of the skill)
  • Look at the Phrase Variable setting
  • Also check the Confidence Variable

You can point those to unique variable names, for example:

  • "$RecognizedPhrase"
  • "$RecognizedConfidence"

That avoids collisions with your TTS/jaw script.


1) Change the Speech Recognition skill variables

In the Speech Recognition skill settings:

  • Set Phrase Variable to something unique like:
    • "$RecognizedPhrase"
  • Set Confidence Variable to something like:
    • "$RecognizedConfidence"

2) Read that variable in Python

Then your script should use:

object_name = getVar("$RecognizedPhrase", "")
print(object_name)

Why your current script is failing

This line is the key issue:

setVar("$SpeechPhrase", "")

If "$SpeechPhrase" is already being used by another part of your project, clearing it right before listening can cause conflicts. Also, your jaw/TTS logic is likely writing to a phrase variable that is not the microphone result.


Suggested Python pattern

Here’s a cleaner version of the speech capture portion:

# Clear only the dedicated recognition variable
setVar("$RecognizedPhrase", "")

# Enable speech recognition if needed
controlCommand("Speech Recognition", "PauseOff")

# Wait until a phrase is recognized
while getVar("$RecognizedPhrase", "") == "":
  sleep(100)

object_name = getVar("$RecognizedPhrase", "")
print(object_name)

If you need to wait for a specific prompt response like OK or Cancel, you can do:

resp = Audio.waitForSpeech(60, "ok", "cancel")

if resp != "ok":
  setVar("$CurrentSpeechPhrase", "ok, I will not learn the " + str(object_name))
  exit()

What I’d recommend in ARC

Since you have multiple scripts interacting, the safest setup is:

  • Use $CurrentSpeechPhrase only for robot speech / jaw animation
  • Use $RecognizedPhrase only for microphone recognition
  • Use $RecognizedConfidence only for confidence filtering

That separation will prevent the two systems from stepping on each other.



If you want, I can help you rewrite your whole script into clean ARC Python so it:

  1. prompts for the object name,
  2. captures the mic phrase correctly,
  3. confirms it,
  4. then starts the camera learning skill.
I am a customer support AI and still learning. Please verify important answers in our support documentation. For advanced AI features, use the AI Script Agent built into ARC.
Author Avatar
Australia
#2   — Edited

@Athena, thanks, yes a rewrite will save me time. Thanks. I did not know that there was a variable = $RecognizedPhrase One question: Can I still use $SpeechPhrase in other scripts or do I now have to change all other uses to $RecognisedPhrase as that would seem to just transfer the clash of variables to $RecognisedPhrase. Thanks again

📚 This thread has been preserved as a helpful resource!

While new comments are no longer being accepted, the information here remains available for learning and reference. Check the most recent comment for additional details.