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 to be identified supports the following two types: |
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'scoding_format,sample_formatorchannelsdoes 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.