aimeasr
v1.0.3
Published
Aime ASR package - A package for streaming audio to a WebSocket for ASR.
Downloads
116
Maintainers
Readme
Aime-ASR
aimeasr
is a simple JavaScript package for streaming audio to a WebSocket for automatic speech recognition (ASR).
Installation
npm install aimeasr
Use ReactJS friendly
import React, { useEffect, useState } from 'react';
import SpeechRecognition from 'aimeasr';
function App() {
const [message, setMessage] = useState('');
const [recognition, setRecognition] = useState(null);
useEffect(() => {
async function init() {
// Custom config
const speechConfig = SpeechRecognition.defaultConfig;
speechConfig.sampleRate = 16000;
speechConfig.speechRecognitionLanguage = "ja-JP";
speechConfig.authorizationToken = "USER-TOKEN";
const stream = await navigator.mediaDevices.getUserMedia({
audio: { echoCancellation: false },
});
const recognitionInstance = new SpeechRecognition(stream, speechConfig);
recognitionInstance.recognizing = (data) => {
console.log("data:", data);
if (data.type === 'recognized') {
setMessage(data.text);
}
};
recognitionInstance.sessionStopped = (s, _e) => {
console.log("Session stopped event.", s);
}
setRecognition(recognitionInstance);
}
init();
}, []);
return (
<div>
<h1>Speech Recognition Demo</h1>
<button onClick={() => recognition?.start()}>Start</button>
<button onClick={() => recognition?.stop()}>Stop</button>
<p>Message: {message}</p>
</div>
);
}
export default App;