pincast-sdk

Speech Recognition Module

The Speech Recognition Module in the Pincast SDK provides an interface for capturing speech input and converting it to text using the Web Speech API. With this module, you can start, stop, and reset the speech recognition process, configure language, continuous listening, and access interim and final text results.

Installation

To install the Pincast SDK and use the Speech Recognition module, follow the Getting Started instructions in the main documentation.

Usage Example

Here’s how to use the Speech Recognition Module:

import { useSpeechRecognition } from 'pincast-sdk';

const { start, stop, reset, finalText, interimText, error, isListening } = useSpeechRecognition({
  lang: 'en-US',
  continuous: true,
  interimResults: true,
});

// Start listening for speech
start();

// Stop listening
stop();

// Access recognized text
console.log("Final Text:", finalText);
console.log("Interim Text:", interimText);

// Reset transcriptions
reset();

// Handle any errors
if (error) {
  console.error("Speech Recognition Error:", error);
}

Configuration Options

The useSpeechRecognition function accepts an optional configuration object to customize the speech recognition process.

API Reference

Properties

Methods

start

Begins the speech recognition process. Resets finalText, interimText, and error before starting.

Usage:

start();

stop

Stops the speech recognition process if it is actively listening.

Usage:

stop();

reset

Clears finalText, interimText, and error.

Usage:

reset();

Example

Here’s a complete example of using the useSpeechRecognition function with various options:

import { useSpeechRecognition } from 'pincast-sdk';

async function recognizeSpeech() {
  const { start, stop, reset, finalText, interimText, error, isListening } = useSpeechRecognition({
    lang: 'en-US',
    continuous: true,
    interimResults: true,
  });

  console.log("Starting speech recognition...");
  start();

  // Listen for 5 seconds, then stop
  setTimeout(() => {
    stop();
    console.log("Stopped listening.");
    console.log("Final Text:", finalText);
    console.log("Interim Text:", interimText);
    if (error) console.error("Recognition Error:", error);
  }, 5000);

  // Reset recognition state if needed
  reset();
}

recognizeSpeech();