0.0.3 • Published 1 year ago

vue-voice-input-component v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Vue voice input component

This component adds a button that allows users to record audio through their microphone using Web APIs‘ MediaRecorder interface and send the audio data to a specified backend server URL for processing. It also provides a component to display the response or other input with a „typing effect“ (similar to chatGPT).

Features

Packages has three components:

  • VoiceButton – allows to send record audio input using Web API MediaRecorder interaface and send it to a specified backend URL
  • VoiceTranscript – allows to display input string as being typed out one letter at a time
  • VoiceTranscriptComponent – combines both components to have an interface component that records audio, sends it to the backend for processing and then displays the response

Usage examples

Install using this command:

npm -i vue-voice-inout-component

Then to use the voice input button:

<script setup lang="ts">
import { VoiceButton } from 'vue-voice-input-component';
</script>

<template>
  <div>
    <VoiceButton
      api-endpoint="http://localhost:3000/api/speech-to-text"
    />
  </div>
</template>

To use the transcript component seperately:

<script setup lang="ts">
import { VoiceTranscript } from 'vue-voice-input-component';
</script>

<template>
  <div>
    <VoiceTranscript
      transcription="This is a test transcription"
    />
  </div>
</template>

And finally the combined component has both the button and the transcript component:

<script setup lang="ts">
import { VoiceTranscriptComponent } from 'vue-voice-input-component';
</script>

<template>
  <div>
    <VoiceTranscriptComponent
      api-endpoint="http://localhost:3000/api/speech-to-text"
    />
  </div>
</template>

Note: the combined VoiceTranscriptComponent expects the backend response to have a transcription key value pairs that is then passed to the transcription component to be validated and displayed.

Component properties

VoiceButton component properties:

NameTypeOptionalDefault valueDescription
apiEndpointStringFalse-API URL where the audio binary data is sent
maxDurationNumberTrue5000msMaximum recording duration
apiHeadersObjectTrueundefinedCustom HTTP request headers that are added to API request
formDataTagStringTrueaudioAudio data value name in API request body
audioContraintsObjectTrue{channelCount: 1, echoCancellation: false, sampleRate: 16000}Audio stream constraints. More options can be found here
blobTypeStringTrueaudio/webm;codecs=opusThe MIME type of blob in which the audio chucks are stored and passed to backend
timesliceNumberTrue1000msThe size of timeslices in milliseconds in which the audio chucks are saved. Note: the max duration is dividated by timeslice to calculate how many timeslices to record so take that into account when setting both properties

Here is the list of emited events:

NamePropertiesDescription
recordingStart-Emits event when the recording is started
recordingStopresponseEmits event when recording is stopped with the API response

VoiceTransript component properties:

NameTypeOptionalDefault valueDescription
transcriptionStringTrue""The transcription string that is displayed by the component
typeSpeedNumberTrue50The speed at which the transcription is written out
singleWordLimitNumberTrue1000The max limit of word used in validating the transcription

The combined VoiceTranscriptComponent has all the properties mention above since it combines both the VoiceButton and VoiceTransript components.

Demo

Here are a few screenshots of the component added to a empty Vue app:

button when not recording

button when recording

button and transcript after recording

Components have minimal styling that could be changed with custom classes. However, it will be updated in the future.

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago