WebkitSpeechRecognition API

Sandipan Kr Bag Mar 10, 2025
WebkitSpeechRecognition API

Introduction

webkitSpeechRecognition is a JavaScript API that enables speech recognition in web applications. It allows users to convert spoken words into text using the browser's built-in speech recognition capabilities.

Features

  • Real-time speech recognition
  • Continuous and single speech modes
  • Language selection
  • Interim results
  • Event-based handling

Browser Support

The webkitSpeechRecognition API is primarily supported in Google Chrome and some Chromium-based browsers. It is not a part of the official Web Speech API standard but is widely used.

Basic Usage

To use webkitSpeechRecognition, follow these steps:

1. Check for Browser Support

if (!('webkitSpeechRecognition' in window)) {
   alert('Your browser does not support Speech Recognition.');
} else {
   console.log('Speech Recognition supported!');
}

 

2. Create an Instance

const recognition = new webkitSpeechRecognition();

3. Configure Properties

recognition.continuous = true; // Keeps listening even after a pause
recognition.interimResults = true; // Provides interim results before final transcript
recognition.lang = 'en-US'; // Sets language to English (US)

4. Handle Events

Start Recognition

recognition.start();

Process Speech Results

recognition.onresult = function(event) {
   let transcript = '';
   for (let i = event.resultIndex; i < event.results.length; i++) {
       transcript += event.results[i][0].transcript;
   }
   console.log('Recognized Speech:', transcript);
};

 

Handle Errors

recognition.onerror = function(event) {
   console.error('Speech Recognition Error:', event.error);
};

Stop Recognition

recognition.onend = function() {
   console.log('Speech recognition stopped.');
};

recognition.stop();

 

Methods of webkitSpeechRecognition

MethodDescription
start()Starts speech recognition
stop()Stops speech recognition
abort()Stops recognition and discards results

Events of webkitSpeechRecognition

EventDescription
onstartTriggered when recognition starts
onresultTriggered when speech is recognized
onspeechendTriggered when speech input stops
onerrorTriggered when an error occurs
onendTriggered when recognition ends

Example Implementation

 

 

Conclusion

The webkitSpeechRecognition API is a powerful tool for adding voice recognition features to web applications. By handling different events and configuring properties, developers can create interactive and accessible web experiences.

Share this article

sndp bag

Sandipan Kr Bag

I'm a dedicated full-stack developer, entrepreneur, and the proud owner of ocec.org.in , hailing from the vibrant country of India. My passion lies in creating informative tutorials and sharing valuable tips that empower fellow artisans in their journey. With a deep-rooted love for technology, I've been an ardent enthusiast of PHP, Laravel, Angular, Vue, Node, JavaScript, jQuery, Codeigniter, and Bootstrap from their earliest days. My philosophy revolves around the values of hard work and unwavering consistency, driving me to continuously explore, create, and share my knowledge with the tech community.

* Hire Me

0 Comments

Load more Comments

Post a Comment

Hint: Please enter between 80 - 300 characters.
ocec.org.in

helllo