Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get sampleRate from AudioContext #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* The JWT token you get after authenticating with our API.
* Check the Authentication section of the documentation for more details.
*/
const accessToken = "";
const uniqueMeetingId = btoa("[email protected]");
const symblEndpoint = `wss://api.symbl.ai/v1/realtime/insights/${uniqueMeetingId}?access_token=${accessToken}`;
* The JWT token you get after authenticating with our API.
* Check the Authentication section of the documentation for more details.
*/
const accessToken = ''
const uniqueMeetingId = btoa('[email protected]')
const symblEndpoint = `wss://api.symbl.ai/v1/streaming/${uniqueMeetingId}?access_token=${accessToken}`;

// Have audio context instance created for getting sample rate and audio processing handler.
const context = new AudioContext();

const ws = new WebSocket(symblEndpoint);

Expand All @@ -25,11 +28,6 @@ ws.onmessage = (event) => {
console.log('Topic detected: ', topic.phrases)
}
}
if (data.type === 'topic_response') {
for (let topic of data.topics) {
console.log('Topic detected: ', topic.phrases)
}
}
if (data.type === 'insight_response') {
for (let insight of data.insights) {
console.log('Insight detected: ', insight.payload.content);
Expand Down Expand Up @@ -62,12 +60,12 @@ ws.onopen = (event) => {
languageCode: 'en-US',
speechRecognition: {
encoding: 'LINEAR16',
sampleRateHertz: 44100,
sampleRateHertz: context.sampleRate, // Get sample rate from browser's audio context
}
},
speaker: {
userId: '[email protected]',
name: 'Example Sample',
userId: '[email protected]',
name: 'Tony Stark',
}
}));
};
Expand All @@ -80,8 +78,6 @@ const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: f
* the WebSocket endpoint for processing.
*/
const handleSuccess = (stream) => {
const AudioContext = window.AudioContext;
const context = new AudioContext();
const source = context.createMediaStreamSource(stream);
const processor = context.createScriptProcessor(1024, 1, 1);
const gainNode = context.createGain();
Expand All @@ -102,5 +98,4 @@ const handleSuccess = (stream) => {
};
};


handleSuccess(stream);
handleSuccess(stream);