Skip to main content

recognize

Available since v1.2.0

Signature:

Speech.recognize(
audio: AudioData | str,
) -> TaskHandle[str]

Description:

Asynchronously recognize an audio clip, return a TaskHandle immediately, and the actual recognition is performed in a background thread.

Parameters:

Parameters

Type

default value

Description

audio

AudioData | str

-

Audio to be identified supports the following two types:
• str: Local audio file path (supports.wavand.mp3 formats, with a maximum size of 3 MB).
• AudioData: Must be mono 16-bit little-endian PCM with a maximum duration of 60 seconds.

Returns:

TaskHandle[str], see "Tasks and Subscriptions / TaskHandle"

Call handle.result() to wait for the recognition to complete and obtain the recognized text.

Exception:

ValueError: Thrown in the following cases:

  • AudioData's coding_format, sample_formator channelsdoes not meet the requirements
  • Audio duration exceeds the limit (AudioDatainput)
  • Unsupported file format (file path input)
  • The file path does not exist (file path input)
  • File size exceeds the limit (file path input)

RuntimeError: Speech recognition call failed (thrown via handle.result()).

Example:

from boosteros.brain import Speech
from boosteros.robots.booster import BoosterRobot

robot = BoosterRobot()
speech = Speech(robot)

handle = speech.synthesize("The weather is really nice today. Welcome to use the Booster bot.")
audio = handle.result()
handle = speech.recognize(audio)
text = handle.result()
print(f"recognize result: {text}")
# Example output: recognize result: The weather is really nice today. Welcome to use the Booster bot.

handle = speech.recognize("/tmp/booster_synthesize.wav")
text = handle.result()
print(f"recognize result: {text}")
# Example output: recognize result: The weather is really nice today. Welcome to use the Booster bot.