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

queue-announcement

v1.2.2

Published

Voice Announcement Library for Queue Management System

Downloads

31

Readme

Queue Announcement Library

Overview

The Queue Announcement Library is a JavaScript library designed for Queue Management Systems. It helps create and play voice announcements based on selected languages and templates. This library can be easily integrated into frontend frameworks like VueJS to enable automatic, dynamic announcements for patients, customers, or any queue-based environment.

Features

  • Multilingual Support: The library supports multiple languages for voice announcements.
  • Template-Based Announcements: Predefined templates are available for different announcement types.
  • Customizable Announcements: Use variables like patient numbers or room numbers to create dynamic, personalized announcements.
  • Sequential Audio Playback: Combines multiple audio files into a single announcement for playback.
  • Promise-Based Handling: Provides a Promise-based API to handle announcement completion and errors effectively.
  • Audio Sprites and Buffers: Uses a single audio sprite file and audio buffer to efficiently manage and play announcement segments.

Installation

To install the library, run the following command:

npm install queue-announcement

Usage

Importing the Library

import VoiceAnnouncement from 'queue-announcement';

Example Usage in a VueJS Application

<template>
  <div id="app">
    <h1>Queue Announcement System</h1>
    <label for="languageSelect">Select Language:</label>
    <select v-model="selectedLanguage">
      <option v-for="language in availableLanguages" :key="language" :value="language">{{ language }}</option>
    </select>
    <label for="templateSelect">Select Template:</label>
    <select v-model="selectedTemplate">
      <option v-for="(template, index) in availableTemplates" :key="index" :value="index">{{ template.name }}</option>
    </select>
    <button @click="prepareAnnouncement">Prepare Announcement</button>
  </div>
</template>

<script>
import VoiceAnnouncement from 'queue-announcement';

export default {
  data() {
    return {
      selectedLanguage: 'kk',
      selectedTemplate: 0,
      availableLanguages: [],
      availableTemplates: [],
      isPlaying: true
    };
  },
  created() {
    this.availableLanguages = VoiceAnnouncement.getAvailableLanguages();
    this.updateTemplates();
  },
  methods: {
    updateTemplates() {
      this.availableTemplates = VoiceAnnouncement.getAvailableTemplates(this.selectedLanguage);
    },
    prepareAnnouncement() {
      if (this.isPlaying) {
        alert('Please wait for the current announcement to finish.')
        return
      }
      const variables = {
        patientNumber: '125',
        roomNumber: '5'
      };
      this.isPlaying = true;
      VoiceAnnouncement.announce(this.selectedLanguage, this.selectedTemplate, variables)
        .then(() => {
        this.isPlaying = false;
          console.log('Announcement finished successfully');
        })
        .catch((error) => {
        this.isPlaying = false;
          console.error('Error during announcement:', error);
        });
    }
  }
};
</script>

Available Functions

getAvailableLanguages()

Returns the list of languages supported by the library.

const languages = VoiceAnnouncement.getAvailableLanguages();

getAvailableTemplates(language)

Returns the available templates for a given language.

const templates = VoiceAnnouncement.getAvailableTemplates('kk');

announce(language, templateId, variables)

Creates and plays an announcement using the specified language, template, and variables. Returns a Promise that resolves when the announcement is finished or rejects if an error occurs.

  • language: The language code (e.g., 'kk', 'ru').
  • templateId: The index of the selected template.
  • variables: An object containing the required values (e.g., patientNumber, roomNumber).
VoiceAnnouncement.announce('kk', 1, { patientNumber: '125', roomNumber: '5' })
  .then(() => {
    console.log('Announcement finished successfully');
  })
  .catch((error) => {
    console.error('Error during announcement:', error);
  });

Customization

To add more languages or templates, modify or create additional language files in the i18n folder. Each language file contains:

  • templates: Predefined announcement structures.
  • digits and numbers: Audio parts for different numbers, used for dynamic announcements.
  • spriteSrc and spriteData: The sprite audio file URL and its Base64-encoded representation used for efficient audio playback.

Example Language File (kk.js)

export const kkI18n = {
  templates: [
    {
      name: "Жүз жиырма бір нөмірлі пациент, бөлмеге өтуіңізге болады",
      parts: [
        { type: "number", part: "patientNumber" },
        { type: "phrase", part: "пациент,", src: "/audio/kk/пациент.mp3" },
        { type: "number", part: "roomNumber" },
        { type: "phrase", part: "бөлмеге өтуіңізге болады", src: "/audio/kk/бөлмеге_өтуіңізге_болады.mp3" }
      ]
    }
  ],
  digits: {
    "0": { src: "/audio/kk/0.mp3" },
    "1": { src: "/audio/kk/1.mp3" },
    // Add other digit audio parts...
  },
  numbers: {
    "00": { src: "/audio/kk/00.mp3" },
    "125": { src: "/audio/kk/125.mp3" }
    // Add other full number audio parts...
  },
  spriteSrc: "/audio/kk/sprite.mp3",
  spriteData: "<Base64-encoded sprite audio>"
};

Development

To develop and test the library locally:

  1. Clone the repository.
  2. Install dependencies using npm install.
  3. Build the library using npm run build.

Contribution

Contributions are welcome! Please feel free to submit a Pull Request or open an issue.