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 🙏

© 2024 – Pkg Stats / Ryan Hefner

chat-bot-rtvi-client

v0.1.4

Published

Chat bot RTVI TS(JS) SDK with RTVI Multimodal interaction configuration.

Downloads

31

Readme

Chat Bot Realtime Voice Inference (RTVI) Web / TS(JS) SDK

Chat bot RTVI TS(JS) SDK with RTVI Multimodal interaction configuration.

Install

yarn add chat-bot-rtvi-client
# or
npm install chat-bot-rtvi-client

Quick Start

Instantiate a VoiceClient instance, wire up the bot's audio, and start the conversation:

import { VoiceClient } from "chat-bot-rtvi-client";

const handleTrackStarted = (track, participant) => {
  if (participant.local || track.kind !== "audio") return;
  const audioEl = document.createElement("audio");
  audioEl.srcObject = new MediaStream([track]);
  document.body.appendChild(audioEl);
  audioEl.play();
};

const voiceClient = new VoiceClient({
  baseUrl: "http://0.0.0.0:4321/bot_join/DailyRTVIBot", // rtvi bots with daily web rtc input/output audio stream
  enableMic: true,
  callbacks: {
    onTrackStarted: handleTrackStarted,
  },
  customHeaders: {"Authorization":"Bearer XXXX"} // JWT auth
});

voiceClient.start();

API

VoiceClient configuration options

baseUrl

The baseUrl points to the RTVI server component for authenticating the user and initializing the required infrastructure for starting the bot conversation. 'http://0.0.0.0:4321/bot_join/DailyRTVIBot' provides demo endpoints for trying out RTVI.

transport (optional)

Configures the transport layer for media streaming, event and message handling. This defaults to the Daily transport layer.

transportURL (optional)

Allows to configure a custom domain to be used in the transport layer.

enableMic (optional)

Enables the user's microphone when starting the conversation. Defaults to true.

enableCam (optional)

Enables the user's camera when starting the conversation. Defaults to false.

callbacks (optional)

Allows to configure callbacks for voice events. It's also possible to dynamically register event handlers using .on.

config (optional)

Allows for further customization of used services, like TTS and LLM.

VoiceClient instance methods

initDevices()

This method initializes the media device selection and allows user's to test and switch media devices before starting the conversation.

start()

Sets up and starts the conversation.

disconnect()

Stops the conversation and tears down all network connections.

getAllMics()

Returns a list of available microphones in the form of MediaDeviceInfo[].

getAllCams()

Returns a list of available cameras in the form of MediaDeviceInfo[].

updateMic(micId: string)

Switches to the microphone identified by the provided micId, which should map a deviceId in the list returned from getAllMics().

updateCam(camId: string)

Switches to the camera identified by the provided camId, which should map a deviceId in the list returned from getAllCams().

enableMic(enable: boolean)

Enables or disables the user's microphone, based on provided enable.

enableCam(enable: boolean)

Enables or disables the user's camera, based on provided enable.

tracks()

Returns all available MediaStreamTracks for the user and bot.

// Return type
{
  local: {
    audio?: MediaStreamTrack;
    video?: MediaStreamTrack;
  },
  bot?: {
    audio?: MediaStreamTrack;
    video?: MediaStreamTrack;
  }
}

updateConfig(config: VoiceClientConfigOptions, { useDeepMerge, sendPartial })

Allows to dynamically update the server-side config for the bot's pipeline.

appendLLMContext(messages: VoiceClientLLMMessage | VoiceClientLLMMessage[])

Appends a message to the live LLM context. Requires the bot to be connected.

say(text: string, interrupt: boolean)

Sends a string to the STT model to be spoken. Requires the bot to be connected. Set interrupt to true to interrupt the bot, if it's currently talking.

interrupt()

Interrupts the bot if it's currently talking. Requires the bot to be connected.

VoiceClient properties

state

Returns the current transport state. Can be one of:

  • "idle" – The VoiceClient is instantiated
  • "initializing"VoiceClient is initializing devices
  • "initialized"VoiceClient devices are initialized
  • "connecting"VoiceClient is setting up the connection to the server
  • "connected"VoiceClient is connected to the server
  • "ready" – The bot is connected and ready to be interacted with
  • "disconnected" – The connection to the server was torn down
  • "error" – An error occurred

selectedMic

Returns the currently selected microphone as MediaDeviceInfo.

selectedCam

Returns the currently selected camera as MediaDeviceInfo.

isMicEnabled

Returns true when the microphone is enabled.

isCamEnabled

Returns true when the camera is enabled.

config

Returns the current config, as set in the constructor, or after calling updateConfig()

llmContext

Returns the current LLM context, as set in config.llm.

transportExpiry

Returns the session expiry time for the transport session, if applicable.

Acknowledge