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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-speech-to-text-gk

v1.1.9

Published

Advanced React speech-to-text library with real-time audio analysis and comprehensive speech metrics

Readme

react-speech-to-text-gk

npm version TypeScript License: MIT React

🎤 Advanced React speech-to-text library with real-time audio analysis, pitch detection, and comprehensive speech metrics.

Perfect for building voice-controlled applications, transcription tools, audio analysis dashboards, and speech-based interfaces.

📋 Table of Contents

✨ Features

🎤 Speech Recognition

  • Real-time speech-to-text with Web Speech API
  • Multi-language support (50+ languages)
  • Interim and final transcript results
  • Configurable silence detection
  • Optimized performance modes

📊 Audio Analysis

  • Volume monitoring - Real-time decibel measurements
  • Pitch detection - Fundamental frequency analysis (60-800 Hz)
  • Spectral centroid - Audio brightness analysis
  • Performance modes - Speed/Balanced/Quality presets
  • Session analytics - Word-level timing and metrics

🔧 Developer Experience

  • TypeScript first - Full type safety and IntelliSense
  • Zero configuration - Works out of the box
  • Lightweight - Only 1 dependency (pitchy)
  • React hooks - Modern, idiomatic React patterns
  • Modular design - Use only what you need

📦 Installation

# npm
npm install react-speech-to-text-gk

# yarn
yarn add react-speech-to-text-gk

# pnpm
pnpm add react-speech-to-text-gk

🎮 Live Demo

Try the interactive demo to see all features in action:

⚡ Quick Start

Basic Speech Recognition

import { useSpeechToText } from 'react-speech-to-text-gk';

function App() {
  const { isListening, transcript, toggleListening } = useSpeechToText();

  return (
    <div>
      <button onClick={toggleListening}>
        {isListening ? '🛑 Stop' : '🎤 Start'} Listening
      </button>
      <p>{transcript}</p>
    </div>
  );
}

With Real-time Audio Metrics

import { useSpeechToText, PerformanceMode } from 'react-speech-to-text-gk';

function VoiceAnalyzer() {
  const {
    isListening,
    transcript,
    interimTranscript,
    audioMetrics,
    toggleListening,
    clearTranscript
  } = useSpeechToText({
    language: 'en-US',
    performanceMode: PerformanceMode.BALANCED
  });

  return (
    <div>
      <div>
        <button onClick={toggleListening}>
          {isListening ? 'Stop' : 'Start'} Listening
        </button>
        <button onClick={clearTranscript}>Clear</button>
      </div>
      
      {/* Real-time metrics */}
      {isListening && (
        <div style={{ margin: '10px 0' }}>
          <div>Volume: {audioMetrics.currentVolume.toFixed(1)}%</div>
          <div>Pitch: {audioMetrics.currentPitch || 'N/A'} Hz</div>
        </div>
      )}
      
      {/* Transcription */}
      <div>
        <strong>Final:</strong> {transcript}
        {interimTranscript && (
          <em style={{ color: '#666' }}> {interimTranscript}</em>
        )}
      </div>
    </div>
  );
}

📚 API Reference

useSpeechToText(config?: SpeechToTextConfig)

The main hook that provides speech recognition with real-time audio analysis.

Parameters

| Property | Type | Default | Description | |----------|------|---------|-------------| | language | string | 'es-ES' | Language code (supported languages) | | silenceTimeout | number | 700 | Silence detection timeout in milliseconds | | optimizedMode | boolean | true | Enable optimized recognition (fewer alternatives, faster) | | performanceMode | PerformanceMode | BALANCED | Performance profile (SPEED/BALANCED/QUALITY) | | audioConfig | object | {} | Audio constraints for getUserMedia API |

Performance Modes

enum PerformanceMode {
  SPEED = 'speed',      // 🏃‍♂️ Low latency, minimal CPU usage
  BALANCED = 'balanced', // ⚖️ Optimal balance (default)
  QUALITY = 'quality'   // 🎯 Maximum accuracy, higher CPU usage
}

Return Values

| Property | Type | Description | |----------|------|-------------| | isListening | boolean | Current listening state | | transcript | string | Final transcript text | | interimTranscript | string | Interim (temporary) transcript | | isSupported | boolean | Browser support check | | silenceDetected | boolean | Silence detection state | | sessionMetadata | SessionMetadata \| null | Complete session analysis | | audioMetrics | AudioMetrics | Real-time audio data | | chartData | ChartData | Chart-ready data | | toggleListening | () => Promise<void> | Start/stop listening | | clearTranscript | () => void | Clear all data | | copyMetadataToClipboard | () => Promise<{success: boolean; message: string}> | Export function |

useAudioAnalysis(performanceMode?: PerformanceMode)

Standalone hook for audio analysis without speech recognition.

Return Values

| Property | Type | Description | |----------|------|-------------| | initializeAudioAnalysis | (config?) => Promise<void> | Initialize audio context | | stopAudioAnalysis | () => void | Stop audio analysis | | getAudioData | () => AudioMetrics | Get current audio metrics | | clearAudioData | () => void | Clear stored data |

💡 Examples

Voice-Controlled UI

function VoiceControls() {
  const { transcript, isListening, toggleListening } = useSpeechToText({
    language: 'en-US'
  });

  // Simple voice commands
  useEffect(() => {
    const command = transcript.toLowerCase();
    if (command.includes('navigate home')) {
      // Handle navigation
    } else if (command.includes('search for')) {
      // Handle search
    }
  }, [transcript]);

  return (
    <button onClick={toggleListening} disabled={!isSupported}>
      {isListening ? 'Listening...' : 'Voice Control'}
    </button>
  );
}

Transcription Tool

function TranscriptionApp() {
  const {
    transcript,
    interimTranscript,
    isListening,
    sessionMetadata,
    toggleListening,
    copyMetadataToClipboard
  } = useSpeechToText({
    language: 'en-US',
    silenceTimeout: 2000,
    performanceMode: PerformanceMode.QUALITY
  });

  return (
    <div>
      <div className="controls">
        <button onClick={toggleListening}>
          {isListening ? 'Stop Recording' : 'Start Recording'}
        </button>
        {sessionMetadata && (
          <button onClick={copyMetadataToClipboard}>
            Export Session Data
          </button>
        )}
      </div>
      
      <div className="transcript">
        {transcript}
        <span style={{ color: '#666' }}>{interimTranscript}</span>
      </div>
      
      {sessionMetadata && (
        <div className="stats">
          <p>Duration: {(sessionMetadata.totalDuration / 1000).toFixed(1)}s</p>
          <p>Words: {sessionMetadata.words.length}</p>
          <p>Avg WPM: {((sessionMetadata.words.length / sessionMetadata.totalDuration) * 60000).toFixed(0)}</p>
        </div>
      )}
    </div>
  );
}

Audio Analysis Dashboard

function AudioDashboard() {
  const {
    audioMetrics,
    sessionMetadata,
    isListening,
    toggleListening
  } = useSpeechToText({
    performanceMode: PerformanceMode.QUALITY,
    silenceTimeout: 1500
  });

  return (
    <div className="dashboard">
      <button onClick={toggleListening}>
        {isListening ? 'Stop Analysis' : 'Start Analysis'}
      </button>
      
      {isListening && (
        <div className="real-time-metrics">
          <div className="metric">
            <h4>Volume</h4>
            <div className="volume-bar">
              <div style={{ width: `${audioMetrics.currentVolume}%` }} />
            </div>
            <span>{audioMetrics.currentVolume.toFixed(1)}%</span>
          </div>
          
          <div className="metric">
            <h4>Pitch</h4>
            <span>{audioMetrics.currentPitch || 'N/A'} Hz</span>
          </div>
          
          <div className="metric">
            <h4>Spectral Centroid</h4>
            <span>{audioMetrics.currentSpectralCentroid || 'N/A'} Hz</span>
          </div>
        </div>
      )}
    </div>
  );
}

⚙️ Configuration Guide

Performance Modes Comparison

| Mode | FFT Size | Update Rate | CPU Usage | Accuracy | Best For | |------|----------|-------------|-----------|----------|----------| | SPEED | 1024 | 15 FPS | Low ⚡ | 90%+ | Real-time apps | | BALANCED | 2048 | 20 FPS | Medium ⚖️ | 95%+ | General use | | QUALITY | 4096 | 30 FPS | High 🔥 | 98%+ | Audio analysis |

Recommended Configurations

// 🏃‍♂️ Real-time conversation
const speedConfig = {
  performanceMode: PerformanceMode.SPEED,
  silenceTimeout: 500,
  optimizedMode: true
};

// 🎯 High-quality transcription
const qualityConfig = {
  performanceMode: PerformanceMode.QUALITY,
  silenceTimeout: 1500,
  optimizedMode: false
};

// ⚖️ General purpose
const balancedConfig = {
  performanceMode: PerformanceMode.BALANCED,
  silenceTimeout: 700,
  optimizedMode: true
};

🚀 Performance

Optimizations

  • Real-time processing - Sub-100ms latency
  • 🧠 Smart memory management - Efficient garbage collection
  • 📊 Optimized algorithms - Single-pass calculations
  • 🎯 Early termination - Pitch detection with confidence thresholds
  • 📈 Data bucketing - Efficient chart data generation

Benchmarks

| Feature | Performance | Memory Usage | |---------|-------------|--------------| | Speech Recognition | ~50ms latency | ~2MB | | Audio Analysis | 60 FPS | ~1MB | | Pitch Detection | 90% accuracy | Minimal |

🔧 Browser Support

| Browser | Speech Recognition | Audio Analysis | Status | |---------|-------------------|----------------|---------| | Chrome 25+ | ✅ Full | ✅ Full | 🟢 Recommended | | Safari 14.1+ | ✅ Full | ✅ Full | 🟢 Supported | | Edge 79+ | ✅ Full | ✅ Full | 🟢 Supported | | Firefox | ❌ No | ✅ Full | 🟡 Partial |

🔍 Troubleshooting

Common Issues

"Speech recognition not supported"

const { isSupported } = useSpeechToText();

if (!isSupported) {
  return <div>Please use Chrome, Safari, or Edge</div>;
}

"Microphone permission denied"

const { toggleListening } = useSpeechToText();

try {
  await toggleListening();
} catch (error) {
  console.log('Microphone access denied');
}

Performance issues

// Use SPEED mode for better performance
const { ... } = useSpeechToText({
  performanceMode: PerformanceMode.SPEED
});

Debug Mode

const { audioMetrics } = useSpeechToText();

// Monitor performance
console.log('Volume data points:', audioMetrics.volumeData.length);
console.log('Current volume:', audioMetrics.currentVolume);

📚 TypeScript Support

Full TypeScript support with comprehensive type definitions:

import {
  // Main hook
  useSpeechToText,
  useAudioAnalysis,
  
  // Configuration types
  SpeechToTextConfig,
  PerformanceMode,
  
  // Data types
  AudioMetrics,
  SessionMetadata,
  WordMetadata,
  ChartData,
  
  // Utility types
  generateSessionMetadata,
  generateChartData
} from 'react-speech-to-text-gk';

🎯 Use Cases

  • 🎤 Voice-controlled interfaces
  • 📝 Transcription applications
  • 📊 Audio analysis tools
  • 🎵 Music applications
  • 🗣️ Speech therapy tools
  • 🎙️ Podcast analytics
  • 📱 Accessibility features

📄 License

MIT License - feel free to use in commercial projects.

🧪 Development

# Install dependencies
npm install

# Build the package
npm run build

# Run example app
npm run example:install
npm run example:start

# Development mode (watch)
npm run dev

🤝 Contributing

We welcome contributions! Please see our Contributing Guide.

Quick Start

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Made with ❤️ for the React community

⭐ Star on GitHub🐛 Report Bug💡 Request Feature