Speaker
robot.speaker controls the robot's overall hardware volume — separate from any individual media lane's volume (see Audio). These examples assume you already have a connected robot — see Connection if you haven't set one up yet.
Setup
<script src="https://cdn.jsdelivr.net/npm/@luxai-qtrobot/robot-sdk/dist/qtrobot-sdk.umd.js"></script>
npm install @luxai-qtrobot/robot-sdk
Get and set volume
const vol = await robot.speaker.getVolume()
console.log(`Current speaker volume: ${vol.toFixed(2)}`)
await robot.speaker.setVolume({ value: 0.8 })
console.log(`Volume after set: ${(await robot.speaker.getVolume()).toFixed(2)}`)
await robot.speaker.setVolume({ value: 0.7 })
Volume isn't perfectly linear
Because of how QTRP's internal audio system handles volume, the perceived loudness doesn't scale evenly with the value you set — for example, going from 0.5 to 0.7 may sound only slightly louder, while going from 0.8 to 0.9 can be a much bigger jump. Worth keeping in mind when picking a default volume or building a volume slider.
Mute and unmute
await robot.speaker.mute()
await new Promise(r => setTimeout(r, 2000))
await robot.speaker.unmute()
Next steps
Continue with the Audio tutorial, or see the full robot.speaker namespace in the TypeScript/Node.js API Reference.