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

voicegpt-assistant

v1.0.7

Published

A voice assistant for GPT.

Readme

VoiceGPT Assistant

The voicegpt-assistant package integrates OpenAI's API with custom functions, enabling both voice and text-based interactions with an AI assistant. This guide will walk you through the setup and usage of the assistant within your application.

Installation

To install the package, run the following command:

npm install voicegpt-assistant

Usage

Example

Below is an implementation that demonstrates how to build a basic voice interaction and chat interface using the useConversation and useSpeechRecognition hooks from the voicegpt-assistant package.

// lib/siri.ts

import { OpenAI } from "voicegpt-assistant";

/**
* Define a set of tools (functions) to extend OpenAI's interaction capabilities.
* Each tool represents a custom function with parameters and a trigger for execution.
*/
const tools = [
 {
   name: "your function name", // The name of the function being defined
   description: "your function description", // A description of what this function does
   parameters: "define parameters", // The expected parameters for the function
   /**
    * Trigger the function with specified arguments or OpenAI response.
    * @param {object} data - Contains arguments from the client or response from OpenAI.
    * @param {any} data.args - Additional arguments passed from the client.
    * @param {any} data.response - The response received from OpenAI's API.
    */
   trigger: async (data: { args?: any; response?: any } | void) => {
     // Function implementation logic goes here
   },
 },
];

/**
* Initialize and configure OpenAI with custom functions defined in the `tools` array.
* The AI object contains all custom-defined tools that can be used to interact with OpenAI.
*/
export const {
 openai, // The base OpenAI object configured with API key and options
 ...AI,  // A spread of all the custom-defined tools
} = OpenAI({
 configure: {
   // Optionally specify your OpenAI organization ID
   // organization: "org-yourorg",
   apiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY!, // Set your OpenAI API key from the environment
   dangerouslyAllowBrowser: true, // Enable usage in browser environments
 },
 functions: tools, // Register the defined tools (custom functions)
});
// components/siri.tsx 
"use client";

import { useEffect, useState } from "react";
import { useConversation, useSpeechRecognition } from "voicegpt-assistant";
import { AI } from "@/lib/siri";

/**
 * Siri Component
 * This component enables a chat interface allowing users to interact with the AI via voice or text.
 */
export function Siri() {
  const [message, setMessage] = useState(""); // Message input state
  const [loading, setLoading] = useState(false); // Loading state for API calls

  // Hooks from `voicegpt-assistant` to manage conversation history and voice recognition
  const { messages, updateMessages, clearMessages } = useConversation("siriMessages");
  const {
    listening, // Listening state for voice recognition
    setListening, // Toggle for activating/deactivating listening
    transcript, // Captured speech transcript
    setTranscript, // Function to reset the transcript
    error, // Speech recognition error
    setError, // Function to reset the error
  } = useSpeechRecognition({
    key: "Hi Siri", // Optional: Key phrase to start listening (for voice control)
    recognitionOptions: {
      lang: "en-US", // Language setting for voice recognition
      continuous: true, // Keep listening continuously for voice input
    },
  });

  /**
   * Effect to update the message when voice transcript is available.
   * Also, handle any errors that occur during speech recognition.
   */
  useEffect(() => {
    if (transcript) {
      setMessage((prevMessage) => prevMessage + " " + transcript); // Append transcript to the message
      setTranscript(null); // Reset the transcript
    }

    if (error) {
      console.error("Speech recognition error:", error); // Log any errors
      setError(null); // Reset the error state
    }
  }, [transcript, error]);

  /**
   * Form submission handler
   * This function handles the submission of messages to the AI using the `AI.callChatGPTWithFunctions` function.
   */
  const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault(); // Prevent the form from refreshing the page
    if (!message.trim()) return; // Prevent sending empty messages

    setLoading(true); // Start loading state during API call

    // Call OpenAI API with the user's message and update the conversation history
    const updatedMessages = await c.callChatGPTWithFunctions({
      userMessage: message, // The message from the user
      existingMessages: messages, // Previous conversation messages
      args: {}, // Additional arguments (if any)
    });

    if (updatedMessages) {
      updateMessages(updatedMessages); // Update the conversation state with the new messages
      setMessage(""); // Clear the input after the message is sent
    }

    setLoading(false); // End loading state after the API call
  };

  return (
    <div>
      <h1>Chat with AI</h1>

      {/* Display the conversation history */}
      <div className="container h-60 w-full overflow-y-auto border py-4">
        {messages?.length ? (
          messages.map((message, index) => (
            <div
              key={index}
              className={`my-4 flex items-center ${
                message.role === "user" ? "justify-end" : "justify-start"
              }`}
            >
              <p
                className={`w-fit rounded-md px-2 py-1 ${
                  message.role === "user"
                    ? "bg-primary text-primary-foreground"
                    : "bg-secondary text-secondary-foreground"
                }`}
              >
                {message.content}
              </p>
            </div>
          ))
        ) : (
          <div className="flex h-full flex-1 items-center justify-center">
            <p>No Messages Yet</p>
          </div>
        )}
      </div>

      {/* Message input and controls */}
      <form onSubmit={handleSubmit}>
        <textarea
          value={message}
          onChange={(e) => setMessage(e.target.value)} // Update message state
          placeholder="Message AI..."
          disabled={loading || listening} // Disable the input if loading or listening
          className="min-h-20 w-full"
        />
        <div>
          <button type="button" onClick={clearMessages} disabled={loading || listening}>
            Clear History
          </button>
          <button type="button" onClick={() => setListening((prev) => !prev)} disabled={loading}>
            {listening ? "Stop Listening" : "Start Listening"}
          </button>
          <button type="submit" disabled={loading || listening}>
            {loading ? "Sending..." : "Send"}
          </button>
        </div>
      </form>
    </div>
  );
}

Features

  • Voice Interaction: Enables users to communicate with the AI via voice commands.
  • Custom Functions: Easily extendable with custom API interactions.
  • Chat History: Maintains a log of the conversation.

Contributing

To contribute, please fork the repository, make your changes, and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

For questions or feedback, feel free to reach out: