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

@voicefield/react

v0.2.9

Published

React hook and components for Voicefield voice input

Readme

@voicefield/react

React hook and components for adding voice input to any web field. Scan a QR code with your phone, speak, and text appears in your desktop browser. Part of Voicefield.

Install

npm install @voicefield/react @voicefield/server

No API key needed — works immediately with the browser's built-in speech recognition.

Peer dependencies: react >= 18, react-dom >= 18. Optional: @soniox/client >= 2.0 for Soniox STT provider.

Try the demo app — clone github.com/tatargabor/voicefield and run pnpm install && pnpm build && cd apps/example && pnpm dev. For phone testing: ngrok http 3000 and open the HTTPS URL on desktop.

Quick Start

import { useVoicefield, QRPopup } from "@voicefield/react"
import { useRef } from "react"

function SearchBar() {
  const inputRef = useRef<HTMLInputElement>(null)

  const vf = useVoicefield({
    serverUrl: "/api/voice",
    language: "en",
  })

  vf.register("search", "Search", inputRef)

  return (
    <>
      <input ref={inputRef} placeholder="Search..." />
      <button onClick={() => vf.showQR()}>🎤</button>
      <QRPopup
        pairingCode={vf.pairingCode}
        secret={vf.secret}
        serverUrl={vf.serverUrl}
        phoneUrl={vf.phoneUrl}
        isVisible={vf.isQRVisible}
        onClose={vf.hideQR}
      />
    </>
  )
}

API Reference

useVoicefield(config)

The main hook. Creates and manages a voice session.

Config

| Prop | Type | Required | Description | |------|------|----------|-------------| | serverUrl | string | Yes | Path to your Voicefield API route (e.g., /api/voice) | | language | string \| string[] | Yes | STT language(s) — e.g., "en", "hu", ["en", "hu"] | | phoneUrl | string | No | Phone page URL. Default: https://voicefield.dev. Set to "" for local mode | | externalServerUrl | string | No | Public URL the phone uses to reach your server (for tunnels/production) |

Return value

| Property | Type | Description | |----------|------|-------------| | sessionId | string \| null | Current session ID | | pairingCode | string \| null | 6-digit code for manual pairing | | secret | string \| null | Session secret (included in QR) | | sessionState | SessionState \| "disconnected" \| null | Current session state | | isPaired | boolean | True when phone is connected | | isRecording | boolean | True when phone is actively recording | | isQRVisible | boolean | QR popup visibility state | | fields | VoiceField[] | Registered voice fields | | activeFieldId | string \| null | Currently active field | | serverUrl | string | Resolved external server URL | | phoneUrl | string | Resolved phone page URL |

| Method | Description | |--------|-------------| | showQR() | Show the QR pairing popup (creates session if needed) | | hideQR() | Hide the QR popup | | endSession() | End the current voice session | | switchField(fieldId) | Switch the active voice target field | | register(id, label, element?, setterFn?) | Register a field for voice input | | unregister(id) | Remove a registered field |

register(id, label, element?, setterFn?)

Register a field that can receive voice input.

// Option A: DOM element — voicefield sets .value directly
const inputRef = useRef<HTMLInputElement>(null)
vf.register("email", "Email", inputRef.current)

// Option B: Setter function — for controlled inputs or custom behavior
const [text, setText] = useState("")
vf.register("notes", "Notes", null, (value, isFinal) => {
  if (isFinal) {
    setText(prev => prev + (prev ? " " : "") + value)
  }
})

<QRPopup />

Renders a modal overlay with the QR code and manual pairing code.

<QRPopup
  pairingCode={vf.pairingCode}
  secret={vf.secret}
  serverUrl={vf.serverUrl}
  phoneUrl={vf.phoneUrl}
  isVisible={vf.isQRVisible}
  onClose={vf.hideQR}
  className="my-custom-overlay"  // optional: override default styles
/>

Phone Page (@voicefield/react/phone)

Mount the phone microphone page in your own app for local development (no tunnel needed):

// app/mic/page.tsx
"use client"
export { Mic as default } from "@voicefield/react/phone"

This renders the full phone UI (code entry → pairing → recording → transcript). When accessed via QR scan, the ?server=...&code=...&secret=... params auto-pair.

Multi-field Usage

Register multiple fields and let the phone switch between them:

function ContactForm() {
  const nameRef = useRef<HTMLInputElement>(null)
  const emailRef = useRef<HTMLInputElement>(null)
  const messageRef = useRef<HTMLTextAreaElement>(null)

  const vf = useVoicefield({ serverUrl: "/api/voice", language: "en" })

  vf.register("name", "Name", nameRef)
  vf.register("email", "Email", emailRef)
  vf.register("message", "Message", messageRef)

  return (
    <form>
      <input ref={nameRef} placeholder="Name" onFocus={() => vf.switchField("name")} />
      <input ref={emailRef} placeholder="Email" onFocus={() => vf.switchField("email")} />
      <textarea ref={messageRef} placeholder="Message" onFocus={() => vf.switchField("message")} />
      <button type="button" onClick={() => vf.showQR()}>🎤 Voice Input</button>
      <QRPopup {...vf} isVisible={vf.isQRVisible} onClose={vf.hideQR} />
    </form>
  )
}

The phone UI shows a field selector dropdown — the user can switch which field receives dictation.

Deployment Modes

| Mode | phoneUrl | externalServerUrl | When to use | |------|-----------|--------------------:|-------------| | Local (LAN) | "" | Auto-detected | Development — phone on same WiFi | | Hosted | (default) | Your public URL | Production with voicefield.dev | | Self-hosted | Your domain | Your domain | Enterprise / full control |

See the deployment guide for detailed setup instructions.

License

MIT