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

@bream-is-a-fish/aimet-asr-react-client

v1.0.3

Published

React client for connecting with AIMET global ASR

Downloads

25

Readme

AIMET ASR React Client

A React library for connecting with AIMET global ASR (Automatic Speech Recognition) services. Provides hooks and providers for audio recording and real-time transcription.

Installation

npm install @bream-is-a-fish/aimet-asr-react-client

Features

  • 🎤 Audio Recording - Record audio with configurable formats and quality
  • 📝 Real-time Transcription - Live speech-to-text with WebSocket connection
  • 🔄 WebSocket Management - Automatic reconnection and connection handling

Quick Start

Using the Transcribe Module

For real-time transcription, wrap your app with TranscribeProvider:

import { TranscribeProvider } from '@bream-is-a-fish/aimet-asr-react-client';

function App() {
  return (
    <TranscribeProvider>
      <YourApp />
    </TranscribeProvider>
  );
}

Then use the transcription hooks in your components:

import {
  AudioFile,
  ErrorResponse,
  GcpSpeechResponse,
  TranscribeActionContext,
  TranscribeStateContext,
  TranscribeConnectionParams,
} from "@bream-is-a-fish/aimet-asr-react-client";

const useMyTranscribe = ({ onTranscription }) => {
  const transcriptionRef = useRef<string[]>([""]);
  const {
    addTranscribeListener,
    removeTranscribeListener,
    startTranscribing,
    stopTranscribing,
    stopTranscribeKeepSocket,
    resumeTranscribe,
  } = useContext(TranscribeActionContext);
  const { serviceInitialized } = useContext(TranscribeStateContext);

  // Set up transcribe callbacks when component mounts
  useEffect(() => {
    // Make sure to check for serviceInitialized to be true first
    // Before setting up callbacks
    if (!serviceInitialized) return;

    const onSpeech = (response: GcpSpeechResponse) => {
        // Example of how to handle transcription
        if (response.is_final) {
            transcriptionRef.current = [
                ...transcriptionRef.current,
                response.alternatives[0]?.transcript ?? "",
            ];
        } else {
            transcriptionRef.current[transcriptionRef.current.length - 1] =
                response.alternatives[0]?.transcript ?? "";
        }
        onTranscription(transcriptionRef.current);
    };

    const onError = (response: ErrorResponse) => {};
    const onRecordingStart = () => {};
    const onRecordingStop = (audioFile: AudioFile) => {};

    addTranscribeListener("onSpeech", onSpeech);
    addTranscribeListener("onError", onError);
    addTranscribeListener("onRecordingStart", onRecordingStart);
    addTranscribeListener("onRecordingStop", onRecordingStop);

    return () => {
      removeTranscribeListener("onSpeech", onSpeech);
      removeTranscribeListener("onError", onError);
      removeTranscribeListener("onRecordingStart", onRecordingStart);
      removeTranscribeListener("onRecordingStop", onRecordingStop);
    };
  }, [serviceInitialized]);

  const startTranscribe = async () => {
    // ...
    await startTranscribing({
      base_url: // ...,
      access_token: // ...,
      caller_service: // app name e.g. braindi,
      caller_ref_id: // e.g. test_id,
    });
  };

  const resumeTranscribe = async () => {
    await resumeTranscribe({
      base_url: // ...,
      access_token: // ...,
      caller_service: // app name e.g. braindi,
      caller_ref_id: // e.g. test_id,
    })
  }

  return {
    startTranscribe,
    startTranscribe,
    resumeTranscribe,
    stopTranscribeKeepSocket,
  };
};

Using Only the Recorder Module

For audio recording without transcription, wrap your app with RecorderProvider:

import { RecorderProvider } from '@bream-is-a-fish/aimet-asr-react-client';

function App() {
  return (
    <RecorderProvider>
      <YourApp />
    </RecorderProvider>
  );
}

Then use the recorder context in your components:

import { RecorderContext, AudioFile } from "@bream-is-a-fish/aimet-asr-react-client";

const RecordingComponent = () => {
  // Use the RecorderProvider context
  const { isRecording: recorderIsRecording, startRecord, stopRecord, requestPermission } =
    useContext(RecorderContext);

  const startRecording = async () => {
    try {
        await requestPermission();
        await startRecord();
        // ...
    } catch (error) {
        // ...
    }
  };

  const handleRecordFinish = async () => {
    try {
        const audioFile = await stopRecord();
        if (!audioFile) {
            throw new Error("Failed to get audio file from recording");
        }
        
        // Process the audio file
        console.log("Audio file:", audioFile);
        setIsRecording(false);
    } catch (error) {
        // ...
    }
  };

  return (<div>...</div>);
};

Accessing Media Stream

For advanced use cases where you need direct access to the media stream:

import { RecorderContext } from "@bream-is-a-fish/aimet-asr-react-client";

const useAudioVisualizer = () => {
  const { recorderServiceRef } = useContext(RecorderContext);
  
  const startVisualize = () => {
    // Access the underlying media stream
    let stream = recorderServiceRef?.current?.getMediaStream();
    // Use to start audio visualizer
  };

  return (
   // ...
  );
};

API Reference

Providers

TranscribeProvider

Provides transcription context to child components.

RecorderProvider

Provides audio recording context to child components.

Hooks

useTranscribe()

Hook for managing transcription state and actions.

useRecorder()

Hook for managing audio recording state and actions.

useIsRecording()

Hook to check if recording is currently active.

Contexts

TranscribeActionContext

Context containing transcription action methods:

  • startTranscribing(params)
  • stopTranscribing()
  • resumeTranscribe(params)
  • addTranscribeListener(event, callback)
  • removeTranscribeListener(event, callback)

TranscribeStateContext

Context containing transcription state:

  • serviceInitialized: boolean

RecorderContext

Context containing recorder methods and state:

  • isRecording: boolean
  • startRecord()
  • stopRecord()
  • requestPermission()
  • recorderServiceRef: RefObject<AudioRecorderService> - Access to the underlying recorder service

Types

TranscribeConnectionParams

interface TranscribeConnectionParams {
  base_url: string;
  access_token: string;
  caller_service: string;
  caller_ref_id?: string;
  model?: string;
}

AudioFile

interface AudioFile {
  blob: Blob;
  format: string;
  fileType: string;
  duration: number;
}