Voice commands in Bubble work through the Web Speech API embedded via JavaScript in an HTML element. This tutorial shows how to add a microphone button that captures spoken words, converts them to text, fills input fields automatically, and triggers Bubble workflows based on recognized voice commands. The approach works in Chrome and Edge browsers.
Overview: Voice Commands in Bubble
This tutorial walks you through adding speech-to-text voice input to your Bubble app. You will embed JavaScript in an HTML element that listens to the microphone, converts speech to text, and sends that text to Bubble elements and workflows. This is useful for hands-free form filling, accessibility features, or voice-controlled navigation.
Prerequisites
- A Bubble app on any plan
- Basic understanding of Bubble's Design tab and HTML elements
- Google Chrome or Microsoft Edge browser
- Microphone access on your device
Step-by-step guide
Add a microphone button and output display
Add a microphone button and output display
In the Design tab, drag a Button element onto your page and label it 'Start Listening' with a microphone icon. Below it, add a Text element for displaying recognized speech and an Input element for voice-to-text filling. Give each element a descriptive ID: set the Button's ID to 'mic-button', the Text element's ID to 'speech-output', and the Input's ID to 'voice-input'. Enable ID attributes first in Settings → General → 'Expose the option to add an ID attribute to HTML elements'.
Expected result: Your page has a microphone button, a text display area, and an input field, each with a unique HTML ID.
Add the Web Speech API JavaScript via HTML element
Add the Web Speech API JavaScript via HTML element
Drag an HTML element onto your page and paste the JavaScript code that initializes the Web Speech API. The script starts listening when the microphone button is clicked and sends the recognized text to your Bubble elements by programmatically setting the input value and dispatching an input event.
1<script>2document.addEventListener('DOMContentLoaded', function() {3 var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;4 if (!SpeechRecognition) {5 var output = document.getElementById('speech-output');6 if (output) output.innerText = 'Voice input not supported in this browser.';7 return;8 }9 var recognition = new SpeechRecognition();10 recognition.continuous = false;11 recognition.interimResults = false;12 recognition.lang = 'en-US';13 var micBtn = document.getElementById('mic-button');14 var output = document.getElementById('speech-output');15 var voiceInput = document.getElementById('voice-input');16 var isListening = false;17 if (micBtn) {18 micBtn.addEventListener('click', function() {19 if (isListening) { recognition.stop(); isListening = false; return; }20 recognition.start();21 isListening = true;22 if (output) output.innerText = 'Listening...';23 });24 }25 recognition.onresult = function(event) {26 var transcript = event.results[0][0].transcript;27 if (output) output.innerText = transcript;28 if (voiceInput) {29 var inputEl = voiceInput.querySelector('input');30 if (inputEl) {31 var setter = Object.getOwnPropertyDescriptor(32 window.HTMLInputElement.prototype, 'value').set;33 setter.call(inputEl, transcript);34 inputEl.dispatchEvent(new Event('input', { bubbles: true }));35 }36 }37 };38 recognition.onerror = function(event) {39 if (output) output.innerText = 'Error: ' + event.error;40 isListening = false;41 };42 recognition.onend = function() {43 isListening = false;44 if (output && output.innerText === 'Listening...')45 output.innerText = 'No speech detected. Try again.';46 };47});48</script>Pro tip: Change recognition.lang to match your users' language, for example 'es-ES' for Spanish or 'fr-FR' for French.
Expected result: The JavaScript is embedded in your page and will initialize when the page loads.
Test basic voice-to-text functionality
Test basic voice-to-text functionality
Preview your app in Google Chrome. Click the microphone button. Your browser will ask for microphone permission — click Allow. Speak a phrase clearly. The Text element should update with your spoken words, and the Input element should fill with the recognized text. If you see 'Error: not-allowed', check that your browser has microphone permissions enabled. If you see 'No speech detected', ensure your microphone is working and try speaking louder.
Expected result: Spoken words appear as text in both the display element and the input field after clicking the microphone button.
Trigger Bubble workflows based on voice commands
Trigger Bubble workflows based on voice commands
To trigger actions based on specific voice commands, use Bubble's 'Do when condition is true' event combined with the input value. In the Workflow tab, create a new event: Do when condition is true. Set the condition to Input voice-input's value contains 'search' or whatever command word you want. Add actions for that command — for example, triggering a search workflow or navigating to a page. Create multiple events for different commands. After each command is processed, use a Set State action to clear the input field so it is ready for the next command.
Expected result: Speaking specific command words triggers corresponding Bubble workflows automatically.
Handle browser compatibility and user experience
Handle browser compatibility and user experience
The Web Speech API is supported in Chrome, Edge, and Safari but not in Firefox. Display a note below the button informing users about browser requirements. Add visual feedback during listening — change the button color or show an animation while the microphone is active. Always provide a text input alternative alongside voice input so users on unsupported browsers can still complete their tasks.
Pro tip: For production apps, always provide a text input fallback alongside voice input for accessibility and browser compatibility.
Expected result: Users see clear feedback when voice input is active, and the feature degrades gracefully in unsupported browsers.
Complete working example
1<script>2document.addEventListener('DOMContentLoaded', function() {3 var SpeechRecognition = window.SpeechRecognition4 || window.webkitSpeechRecognition;5 if (!SpeechRecognition) {6 var output = document.getElementById('speech-output');7 if (output) output.innerText =8 'Voice input not supported in this browser.';9 return;10 }1112 var recognition = new SpeechRecognition();13 recognition.continuous = false;14 recognition.interimResults = false;15 recognition.lang = 'en-US';1617 var micBtn = document.getElementById('mic-button');18 var output = document.getElementById('speech-output');19 var voiceInput = document.getElementById('voice-input');20 var isListening = false;2122 if (micBtn) {23 micBtn.addEventListener('click', function() {24 if (isListening) {25 recognition.stop();26 isListening = false;27 micBtn.style.backgroundColor = '';28 return;29 }30 recognition.start();31 isListening = true;32 micBtn.style.backgroundColor = '#ef4444';33 if (output) output.innerText = 'Listening...';34 });35 }3637 recognition.onresult = function(event) {38 var transcript = event.results[0][0].transcript;39 if (output) output.innerText = transcript;40 if (voiceInput) {41 var inputEl = voiceInput.querySelector('input');42 if (inputEl) {43 var setter = Object.getOwnPropertyDescriptor(44 window.HTMLInputElement.prototype, 'value'45 ).set;46 setter.call(inputEl, transcript);47 inputEl.dispatchEvent(48 new Event('input', { bubbles: true })49 );50 }51 }52 };5354 recognition.onerror = function(event) {55 if (output) output.innerText = 'Error: ' + event.error;56 isListening = false;57 if (micBtn) micBtn.style.backgroundColor = '';58 };5960 recognition.onend = function() {61 isListening = false;62 if (micBtn) micBtn.style.backgroundColor = '';63 if (output && output.innerText === 'Listening...')64 output.innerText = 'No speech detected. Try again.';65 };66});67</script>Common mistakes when implementing Voice Commands in Your Bubble App
Why it's a problem: Testing voice commands in Firefox which does not support the Web Speech API
How to avoid: Always test in Chrome or Edge, and add a browser check to inform users of unsupported browsers
Why it's a problem: Not enabling the ID attribute option in Bubble settings
How to avoid: Go to Settings → General and enable 'Expose the option to add an ID attribute to HTML elements'
Why it's a problem: Forgetting to handle the microphone permission denial
How to avoid: Handle the onerror event and display a message asking the user to enable microphone permissions
Best practices
- Always provide a text input fallback alongside voice input for accessibility
- Display clear visual feedback while actively listening
- Handle all Speech API error events and display user-friendly messages
- Set the recognition language to match your target audience
- Test voice recognition in a quiet environment for best accuracy
- Keep voice commands short and distinct to improve recognition reliability
- Clear the input field after processing a command to prepare for the next one
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I want to add voice-to-text input in my Bubble.io app so users can speak into a search bar instead of typing. How do I use the Web Speech API in a Bubble HTML element?
Help me add a microphone button to my search page. When users click it and speak, the recognized text should fill the search input and automatically trigger a search.
Frequently asked questions
Which browsers support voice commands in Bubble?
The Web Speech API works in Google Chrome, Microsoft Edge, and Safari. Firefox does not support it. Always provide a text input alternative.
Does voice recognition work on mobile devices?
Yes. Chrome on Android and Safari on iOS both support the Web Speech API. Mobile browsers may show their own microphone UI when speech recognition starts.
Can I use voice commands in multiple languages?
Yes. Change the recognition.lang property to any supported BCP 47 language code, such as 'es-ES' for Spanish or 'fr-FR' for French.
Is the voice data sent to external servers?
In Chrome, the Web Speech API sends audio to Google's servers for processing. This is a client-side browser feature and Bubble does not store or process the audio.
Can I make continuous voice recognition that keeps listening?
Yes. Set recognition.continuous = true in the JavaScript code. This keeps the microphone active until you explicitly call recognition.stop().
Can RapidDev help implement voice features in my Bubble app?
Yes. RapidDev can build custom voice command systems including multi-language support, voice-triggered navigation, and integration with AI assistants for your Bubble application.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation