
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
vue-transcribe
Advanced tools
An encapsulated Vue.js component + service for speech-to-text functionality using AWS Transcribe
A lightweight Vue 2 & Vue 3 compatible directive + service bundle for adding a near real-time speech-to-text transcription and voice command execution using WebSocket-based services like Amazon Transcribe.
You can:
<VoiceButton />
for command-style or text-generation mic capturenpm install vue-transcribe
This package requires material design icons to function properly. It is expected that you have this setup in the consuming project. If you don't have it setup yet, do the following:
npm install @mdi/font
main.js
):import '@mdi/font/css/materialdesignicons.css';
// or
import '@mdi/font/css/materialdesignicons.min.css';
You must generate and provide a presigned WebSocket URL to start any transcription. Example (using AWS Transcribe):
import { TranscribeAPI } from 'vue-transcribe';
import axios from 'axios';
async function configure() {
const { data } = await axios.get('/api/transcribe-url'); // Replace with the presignedURL generation endpoint in your setup
TranscribeAPI.setURL(data.url);
TranscribeAPI.setConfigured(true); // ✅ Don't forget this
}
// AWS Transcribe presigned URLs expire every 5 minutes
configure();
setInterval(configure, 5 * 60 * 1000);
⚠️
setConfigured(true)
is required to indicate that a valid transcription URL is available. Without this, the component will not render. This can be used to filter envs as well. e.gTranscribeAPI.setConfigured(process.env.NODE_ENV !== 'development)
<VoiceButton />
ComponentThis button provides a quick way to interact with the API, and can be used in 2 modes - generate
and command
Text generation mode is all about speech to text generation. This means that there has to be an input or textarea field you wish to populate with texts when you speak. The VoiceButton
component relies on an enclosing parent HTMLElement to be able to find the input element of interest. With that, you should have the input
or textarea
of interest, together with the <VoiceButton />
, enclosed within any parent HTMLElement. The order and styling is up to you:
<template>
<div class="input-voice-container">
<textarea class="input"></textarea>
<VoiceButton
:mode="generate"
:disabled="isDisabled"
language-code="en-US"
theme="primary-transparent"
microphone="solid"
max-recording-time="10000"
/>
</div>
</template>
<script>
import { VoiceButton } from 'vue-transcribe';
export default {
components: {
VoiceButton
},
data() {
return {
isDisabled: false
}
}
};
</script>
In command
mode, your app can execute tasks based on matched phrases. You have to setup the command mapping first of all:
TranscribeAPI.setCommandMap([
{
command: 'clear input',
task: () => {
const el = document.querySelector('input');
if (el) el.value = '';
}
},
{
command: 'submit form',
task: () => {
document.querySelector('form')?.submit();
}
},
{
command: 'shut down app',
task: () => {
this.application.shutdown(); // assumption
}
}
]);
Once the command mapping is configured, use the component in your templates like so:
<template>
<VoiceButton
:mode="command"
:disabled="isDisabled"
language-code="en-US"
theme="primary"
microphone="solid"
max-recording-time="10000"
/>
</template>
<script>
import { VoiceButton } from 'vue-transcribe';
export default {
components: {
VoiceButton
},
data() {
return {
isDisabled: false
}
}
};
</script>
Prop | Type | Required | Description |
---|---|---|---|
mode | string | ✅ | Transcription mode - text-generation or custom commands. generate / command |
language-code | string | ❌ | BCP-47 language code (default en-US ) |
max-recording-time | number | ❌ | Max mic capture time in ms (default: 5000 ) |
microphone | string | ❌ | Microphone's style (solid or outline ). default solid |
disabled | boolean | ❌ | If button should be disabled. default false |
theme | string | ❌ | Predefined themes that can be applied - primary (default), secondary , danger . Append -transparent to any of the themes to get a button with transparent background |
expanded | boolean | ❌ | To show or hide label. default is false . |
append | boolean | ❌ | Whether to replace or append to existing text input. For generate mode |
trim-punctuation | boolean | ❌ | Whether to remove trailing punctuations from transcript. For generate mode |
TranscribeAPI
Method | Description |
---|---|
setURL(url: string) | Sets the active transcription WebSocket URL |
setConfigured(boolean) | Enables/disables voice capture |
isConfigured() | Returns current config state |
setCommandMap(array) | Registers global voice commands |
on(event, callback) | Subscribe to 'error' event |
off(event, callback) | Unsubscribe from events |
TranscribeAPI.on('error', (error) => {
console.error('Transcribe error:', error);
});
// Error event structure
{
code: ErrorCodes,
message: String,
details?: ErrorEvent
}
// enum ErrorCodes {
// WS_CONNECTION_FAILED: 'WS_CONNECTION_FAILED',
// AUDIO_CAPTURE_ERROR: 'AUDIO_CAPTURE_ERROR',
// NO_MATCHING_COMMAND: 'NO_MATCHING_COMMAND'
// };
// To unsubscribe
TranscribeAPI.off('error', callback);
import Vue from 'vue';
import {
VoiceButton
TranscribeAPI
} from 'vue-transcribe';
import axios from 'axios';
TranscribeAPI.setCommandMap([
{
command: 'clear input',
task: () => {
const el = document.querySelector('input');
if (el) el.value = '';
}
},
]);
function setURL() {
axios.get('/api/transcribe-url') // You are to set up this endpoint
.then(res => TranscribeAPI.setURL(res.data.url));
}
setURL();
setInterval(setURL, 5 * 60 * 1000);
TranscribeAPI.on('error', err => {
console.error('Transcription error:', err);
// You can trigger a toast, log or do anything of choice here
});
TranscribeAPI.setConfigured(true)
Vue.component('VoiceButton', VoiceButton); // Global registration
TranscribeAPI.isConfigured()
is true
{ command, task }
TranscribeAPI.on('error', cb)
to listen for transcription/command errorsISC
Merge Requests welcome! Please follow existing code style and include docs for any new features or events.
Charles Ugbana
FAQs
An encapsulated Vue.js component + service for speech-to-text functionality using AWS Transcribe
The npm package vue-transcribe receives a total of 2 weekly downloads. As such, vue-transcribe popularity was classified as not popular.
We found that vue-transcribe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.