npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

malivan-voice

v0.1.7

Published

[![npm version](https://badge.fury.io/js/malivan-voice.svg)](https://badge.fury.io/js/malivan-voice) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Downloads

8

Readme

malivan-voice

npm version License: MIT

A powerful and easy-to-use React hook for text-to-speech and speech-to-text functionality, with built-in support for Thai language and audio file processing.

Features

  • 🗣️ Text-to-speech (TTS) functionality
  • 👂 Speech-to-text (STT) functionality
  • 🎵 Audio file processing for speech recognition
  • 🛠️ Customizable options for both TTS and STT
  • 🇹🇭 Built-in support for Thai language
  • 📘 TypeScript support
  • 🚀 Easy integration into React projects
  • 🆓 Free and open-source

Installation

npm install malivan-voice
# or
yarn add malivan-voice

Usage

Here's a basic example of how to use the useSpeech hook:

import React from 'react';
import { useSpeech } from 'malivan-voice';

const SpeechComponent = () => {
  const {
    speak,
    stopSpeaking,
    startListening,
    stopListening,
    processAudioFile,
    transcript,
    isListening,
    isSpeaking,
    isProcessingFile,
    error
  } = useSpeech({
    textToVoiceOptions: { lang: 'th-TH', rate: 1.0 },
    voiceToTextOptions: { lang: 'th-TH', continuous: true }
  });

  const handleFileUpload = (event) => {
    const file = event.target.files?.[0];
    if (file) {
      processAudioFile(file);
    }
  };

  return (
    <div>
      <h1>Speech Demo</h1>
      {error && <p>Error: {error}</p>}
      <div>
        <button onClick={() => speak('สวัสดีครับ')}>Speak</button>
        <button onClick={stopSpeaking} disabled={!isSpeaking}>Stop Speaking</button>
      </div>
      <div>
        <button onClick={startListening} disabled={isListening}>Start Listening</button>
        <button onClick={stopListening} disabled={!isListening}>Stop Listening</button>
      </div>
      <div>
        <input type="file" accept="audio/*" onChange={handleFileUpload} />
      </div>
      <p>Transcript: {transcript}</p>
      <p>Status: 
        {isListening ? 'Listening' : 'Not Listening'}, 
        {isSpeaking ? 'Speaking' : 'Not Speaking'},
        {isProcessingFile ? 'Processing File' : 'Not Processing File'}
      </p>
    </div>
  );
};

API

useSpeech

function useSpeech(options?: UseSpeechOptions): UseSpeechReturn

UseSpeechOptions

The useSpeech hook accepts an optional configuration object with the following properties:

textToVoiceOptions

These options customize the text-to-speech functionality:

  • lang: The language for speech synthesis (e.g., 'th-TH' for Thai)
  • pitch: The pitch of the voice (default is 1, can range from 0 to 2)
  • rate: The speed of speech (default is 1, can range from 0.1 to 10)
  • volume: The volume of speech (default is 1, can range from 0 to 1)
  • voice: A specific SpeechSynthesisVoice object to use for speech

voiceToTextOptions

These options customize the speech recognition functionality:

  • lang: The language for speech recognition (e.g., 'th-TH' for Thai)
  • continuous: Whether to continuously recognize speech (default is false)
  • interimResults: Whether to return interim results while recognizing (default is false)

All of these options are optional. If not provided, the hook will use default values or browser defaults where applicable.

Return Value

| Property | Type | Description | |----------|------|-------------| | speak | (text: string) => void | Converts text to speech | | stopSpeaking | () => void | Stops ongoing speech synthesis | | startListening | () => void | Starts speech recognition | | stopListening | () => void | Stops ongoing speech recognition | | processAudioFile | (file: File) => Promise<void> | Processes an audio file for speech recognition | | transcript | string | Text obtained from speech recognition | | isListening | boolean | Indicates if speech recognition is active | | isSpeaking | boolean | Indicates if text-to-speech is active | | isProcessingFile | boolean | Indicates if an audio file is being processed | | error | string \| null | Error message, if any |

Browser Compatibility

This package uses the Web Speech API and Web Audio API, which are supported in most modern browsers. However, support may vary, especially for older browsers. Please check the browser compatibility for Web Speech API and Web Audio API before using this in production.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any problems or have any questions, please open an issue in the GitHub repository.


Made with ❤️ by Beer Do-san