queue-announcement
v1.2.2
Published
Voice Announcement Library for Queue Management System
Downloads
31
Maintainers
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:
- Clone the repository.
- Install dependencies using
npm install
. - Build the library using
npm run build
.
Contribution
Contributions are welcome! Please feel free to submit a Pull Request or open an issue.