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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nvdigitalsolutions/nvoos-audio

v0.1.0-alpha.3

Published

Browser audio I/O for AI chat: TTS, STT, voice chat with VAD - Extracted from NV Open Operator System

Downloads

98

Readme

@nvdigitalsolutions/nvoos-audio

Browser audio I/O for AI chat: TTS (text-to-speech), STT (speech-to-text / transcription), audio translation, and voice chat with Voice Activity Detection — extracted from the NV Open Operator System WordPress plugin.

Zero external dependencies. Uses only standard browser APIs: MediaRecorder, Web Audio API, SpeechSynthesis, Fetch.

Why this package?

Every conversational AI UI needs audio I/O. This package bundles the full stack in one place:

| Feature | API | |---------|-----| | Text-to-speech playback | attachSpeechButton() | | Stop/resume speech | stopSpeechPlayback() | | Microphone → transcription | handleTranscribeButtonClick() | | File upload → transcription | handleTranscribeFileSelection() | | Audio → English translation | handleTranslateButtonClick() | | Voice chat with VAD | handleVoiceChatButtonClick() | | Feature detection | supportsAudioRecording() |

Installation

npm install @nvdigitalsolutions/nvoos-audio

Quick Start

Text-to-Speech

import { attachSpeechButton } from '@nvdigitalsolutions/nvoos-audio';

// Attach a play/stop button to any message element
const bubble = document.querySelector('.ai-message');
const chatState = {
  config: {
    toolsEndpoint: 'https://your-api.com/wp-json/mcp-ai/v1/tools',
    nonce: 'your-nonce',
  },
  speechCache: {},
};
attachSpeechButton(bubble, null, chatState);

Microphone Transcription

import { handleTranscribeButtonClick, supportsAudioRecording } from '@nvdigitalsolutions/nvoos-audio';

if (supportsAudioRecording()) {
  const btn = document.querySelector('#transcribe-btn');
  const state = { config: { toolsEndpoint: '...', nonce: '...' } };
  const helpers = { setStatus: (container, msg) => console.log(msg) };

  btn.addEventListener('click', () => {
    handleTranscribeButtonClick(btn, state, helpers);
  });
}

Customise CSS Class Names

import { configure } from '@nvdigitalsolutions/nvoos-audio';

configure({
  speechButtonClass: 'my-tts-btn',
  speechEnabledClass: 'my-tts-enabled',
  transcribeRecordingClass: 'my-recording',
  voiceChatRecordingClass: 'my-voice-recording',
});

API

configure(options)

Override default CSS class names. Call once at startup before using any other function.

| Option | Default | |--------|---------| | speechButtonClass | 'wp-mcp-ai-speech-button' | | speechEnabledClass | 'wp-mcp-ai-speech-enabled' | | speechErrorClass | 'wp-mcp-ai-speech-button--error' | | transcribeRecordingClass | 'wp-mcp-ai-chat__transcribe--recording' | | translateRecordingClass | 'wp-mcp-ai-chat__translate--recording' | | voiceChatRecordingClass | 'wp-mcp-ai-chat__voice-chat--recording' | | voiceChatProcessingClass | 'wp-mcp-ai-chat__voice-chat--processing' | | voiceChatListeningClass | 'wp-mcp-ai-chat__voice-chat--listening' |

Object URL Management

import { registerObjectUrl, revokeObjectUrls } from '@nvdigitalsolutions/nvoos-audio';

// Register blob URLs so they can be bulk-revoked on unmount
registerObjectUrl(blobUrl);

// On component teardown / page unload
revokeObjectUrls();

supportsAudioRecording()

Returns true if the browser supports MediaRecorder and getUserMedia.

attachSpeechButton(bubble, text?, state, helpers?)

Appends a play/stop TTS button to bubble. Handles caching, playback lifecycle, and error state internally.

updateSpeechButtonIcon(button, stateName)

Programmatically set the button icon: 'idle' | 'loading' | 'playing'.

stopSpeechPlayback(state, button)

Stop ongoing audio playback and reset the button to idle.

handleTranscribeButtonClick(button, state, helpers?)

Toggle microphone recording. On stop, uploads the audio and calls the transcription tool endpoint. Integrates with wpMcpAiChatTranscription.insertTranscriptionResult().

handleTranscribeFileSelection(input, state, helpers?)

Handle an <input type="file"> change event for audio transcription.

extractTranscriptionResult(response)

Extract the transcription result from a tool API response object.

handleTranslateButtonClick / handleTranslateFileSelection

Same as transcription equivalents but calls the translation endpoint (output is always English).

handleVoiceChatButtonClick(button, state, helpers?)

Toggle voice chat mode. Uses VAD (Voice Activity Detection) to detect end-of-speech, then submits the transcript as a chat message automatically.

updateVoiceChatButtonState(state)

Sync the voice chat button's visual state with state.voiceChatRecording / state.voiceChatProcessing.

wpMcpAiChatTranscription

The transcription service object, exported for direct use:

import { wpMcpAiChatTranscription } from '@nvdigitalsolutions/nvoos-audio';

wpMcpAiChatTranscription.insertTranscriptionResult(state, result, record, formatDuration);

VAD Configuration

Voice Activity Detection constants can be tuned via the state.config object passed to handleVoiceChatButtonClick:

const state = {
  config: {
    toolsEndpoint: '...',
    nonce: '...',
    vadSilenceThresholdMs: 700,    // silence duration before stopping (ms)
    vadMinSpeechDurationMs: 300,   // minimum speech duration to process (ms)
    vadAudioLevelThreshold: -50,   // dB level considered "speech"
  }
};

Browser Support

  • Chrome/Edge 79+ (MediaRecorder + Web Audio)
  • Firefox 90+
  • Safari 15+

TypeScript

Full TypeScript definitions included:

import type { AudioConfig } from '@nvdigitalsolutions/nvoos-audio';

License

MIT — NV Digital Solutions