@lephenix47/speech-to-text-utility
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@lephenix47/speech-to-text-utility

Table of Contents

Introduction

Introducing the @lephenix47/speech-to-text-utility library, a powerful and flexible solution designed for JavaScript and TypeScript developers looking to integrate speech recognition features into their projects. Built with simplicity and extensibility in mind, this library harnesses the power of the browser's Web Speech API to transcribe real-time audio inputs with ease.

Usage

Importing the Library

To begin, you'll need to import the library into your project:

  import { SpeechToText } from '@lephenix47/speech-to-text-utility';

Configuring and Starting Speech Recognition

From here, you can personalize the speech recognition behavior to fit your application's demands. Some notable methods worth mentioning include setting the language, enabling interim results, limiting the number of alternatives, toggling continual recognition, and configuring event callbacks.

Example:

  const speechToText = new SpeechToText();

  speechToText
    .setLanguage('en-US')
    .setInterimResults(true)
    .setMaxAlternatives(5)
    .setContinuous(true)
    .setOnResult((sentence, isFinal) => {
      if (isFinal) {
        console.log(`Received Final Result: "${sentence}"`);
      } else {
        console.log(`Received Intermediate Result: "${sentence}"`);
      }
    });

Ready to embark on recognizing speech? Trigger the speech recognition engine with the startRecognition() method.

  speechToText.startRecognition();

Should you ever decide to halt the recognition midway, rely on the handy stopRecognition() method.

  speechToText.stopRecognition();

Available Methods and Properties

📖 Table of all the methods and properties
Method Description Return Value
setLanguage(language: string) Sets the language for the speech recognition. SpeechToText
setInterimResults(bool: bool) Determines if interim results are included in the recognition. SpeechToText
setMaxAlternatives(num: number) Limits the number of recognition alternatives offered. SpeechToText
setContinuous(bool: bool) Switches on or off the continuous speech recognition mode. SpeechToText
setOnResult(fn: Function) Registers a callback function invoked whenever a speech recognition result occurs. SpeechToText
setOnEnd(fn: Function) Subscribes to the speech recognition ending event. SpeechToText
setOnError(fn: Function) Signs up for the speech recognition error event. SpeechToText
setOnStart(fn: Function) Hooks into the speech recognition initialization event. SpeechToText
setOnAudioStart(fn: Function) Captures the audio capturing commencement event. SpeechToText
setOnSoundStart(fn: Function) Monitors the audio's sonic occurrences triggering the fn callback. SpeechToText
setOnSoundEnd(fn: Function) Observes the conclusion of auditory happenings invoking the fn callback. SpeechToText
setOnSpeechStart(fn: Function) Seizes the moment when vocalizations ignite the fn callback. SpeechToText
setOnSpeechEnd(fn: Function) Records the culmination of verbal articulations summoning the fn callback. SpeechToText
setOnNoMatch(fn: Function) Documents the absence of a match incited by the fn callback. SpeechToText
startRecognition() Commences speech recognition processing. Promise<void>
stopRecognition() Terminates ongoing speech recognition activity. Promise<void>
get maxAlternatives() Retrieves the maximum number of recognition alternatives. number
get continuous() Obtains the status of continuous speech recognition. boolean

Conclusion

Integrating speech recognition into your projects has never been simpler, courtesy of the @lephenix47/speech-to-text-utility library. Benefit from hassle-free integration, robustness, and extensive customizability today! Should you require any assistance or contribute, head over to GitHub and join the community.

Don't hesitate to leave a star rating or review to express appreciation for this open-source endeavor. Happy coding!

Readme

Keywords

none

Package Sidebar

Install

npm i @lephenix47/speech-to-text-utility

Weekly Downloads

2

Version

1.0.1

License

ISC

Unpacked Size

22.5 kB

Total Files

6

Last publish

Collaborators

  • lephenix47