Node-RED Browser Audio Player
The node-red-contrib-play-audio package (current stable version 2.5.0) provides a Node-RED node designed for playing audio directly within the client-side browser context where the Node-RED dashboard or editor is viewed. It specifically leverages the Web Audio API to play raw audio buffers, making it suitable for integrations with other nodes that output audio data, such as Text-to-Speech (TTS) services (e.g., the Watson Text to Speech node). Additionally, it offers basic browser-native Text-to-Speech capabilities for simple string inputs, provided the browser supports this feature. This node is a key component for adding client-side audio feedback or announcements to Node-RED applications, operating exclusively in the browser environment rather than on the Node.js server. Its release cadence follows contributions and updates to Node-RED compatibility.
Common errors
-
Error: Cannot find module 'node-red-contrib-play-audio'
cause The Node-RED node package was not installed correctly or in the correct directory for Node-RED to discover it.fixRun `npm install node-red-contrib-play-audio` in your Node-RED user directory (typically `~/.node-red`). Restart Node-RED after installation. -
Audio not playing in browser / 'Play Audio' node appears green but no sound
cause Browser autoplay policies are blocking the audio, or the browser does not support the Web Audio API, or the browser tab is not active.fixInteract with the browser page (e.g., click an inject button) to satisfy autoplay policies. Ensure your browser is up-to-date and supports the Web Audio API. Keep the Node-RED tab active. -
'Play Audio' node missing from palette after installation.
cause Node-RED was not restarted, or the installation occurred in a different directory than Node-RED's active user directory.fixEnsure Node-RED is restarted after `npm install`. Verify you installed the package in the directory where your Node-RED instance is configured to look for nodes (often `~/.node-red`).
Warnings
- gotcha This node performs audio playback exclusively in the client-side browser where the Node-RED editor or dashboard is accessed. It does not play audio on the Node.js server.
- gotcha Playback relies on the Web Audio API, which may have browser compatibility differences or security restrictions, especially regarding autoplay.
- gotcha When using the Text-to-Speech (TTS) feature, voice quality and availability are dependent on the client browser's native speech synthesis capabilities, which vary significantly across browsers and operating systems.
Install
-
npm install node-red-contrib-play-audio -
yarn add node-red-contrib-play-audio -
pnpm add node-red-contrib-play-audio
Imports
- node-red-contrib-play-audio
import { PlayAudioNode } from 'node-red-contrib-play-audio'npm install node-red-contrib-play-audio
Quickstart
[
{
"id": "a1b2c3d4e5f6g7h8",
"type": "inject",
"z": "z9y8x7w6v5u4t3s2",
"name": "Trigger TTS",
"props": [
{
"p": "payload",
"v": "Hello from Node-RED!",
"vt": "str"
},
{
"p": "topic",
"vt": "msg"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"x": 140,
"y": 100,
"wires": [
[
"h1g2f3e4d5c6b7a8"
]
]
},
{
"id": "h1g2f3e4d5c6b7a8",
"type": "play-audio",
"z": "z9y8x7w6v5u4t3s2",
"name": "Play Audio",
"voice": "default",
"lang": "en-US",
"x": 340,
"y": 100,
"wires": []
}
]