Skip to content

Commit

Permalink
Formatting/spelling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
holtskinner committed Dec 20, 2024
1 parent 931864d commit df4623d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class LiveAudioOutputManager {
constructor() {
this.audioInputContext
this.workletNode
this.initalized = false
this.initialized = false

this.audioQueue = [];
this.isPlaying = false;
Expand All @@ -13,27 +13,27 @@ class LiveAudioOutputManager {


async playAudioChunk(base64AudioChunk) {
try {
if (!this.initalized) {
await this.initializeAudioContext();
}
try {
if (!this.initialized) {
await this.initializeAudioContext();
}

if (this.audioInputContext.state === "suspended") {
await this.audioInputContext.resume();
}
if (this.audioInputContext.state === "suspended") {
await this.audioInputContext.resume();
}

const arrayBuffer = LiveAudioOutputManager.base64ToArrayBuffer(base64AudioChunk);
const float32Data = LiveAudioOutputManager.convertPCM16LEToFloat32(arrayBuffer);
const arrayBuffer = LiveAudioOutputManager.base64ToArrayBuffer(base64AudioChunk);
const float32Data = LiveAudioOutputManager.convertPCM16LEToFloat32(arrayBuffer);

this.workletNode.port.postMessage(float32Data);
} catch (error) {
console.error("Error processing audio chunk:", error);
this.workletNode.port.postMessage(float32Data);
} catch (error) {
console.error("Error processing audio chunk:", error);
}
}
}

async initializeAudioContext() {

if (this.initalized) return;
if (this.initialized) return;

console.log("initializeAudioContext...")

Expand All @@ -43,7 +43,7 @@ class LiveAudioOutputManager {
this.workletNode = new AudioWorkletNode(this.audioInputContext, "pcm-processor");
this.workletNode.connect(this.audioInputContext.destination);

this.initalized = true;
this.initialized = true;
console.log("initializeAudioContext end")
}

Expand Down Expand Up @@ -91,19 +91,19 @@ class LiveAudioInputManager {
sampleRate: 16000,
});

let contraints = {
let constraints = {
audio: {
channelCount: 1,
sampleRate: 16000,
},
}

if (this.deviceId) {
contraints.audio.deviceId = { exact: this.deviceId }
constraints.audio.deviceId = { exact: this.deviceId }
}

this.stream = await navigator.mediaDevices.getUserMedia(
contraints
constraints
);

const source = this.audioContext.createMediaStreamSource(this.stream);
Expand Down Expand Up @@ -232,7 +232,7 @@ class LiveVideoManager {
}

newFrame() {
console.log("capturinng new frame")
console.log("capturing new frame")
const frameData = this.captureFrameB64()
this.onNewFrame(frameData)
}
Expand Down Expand Up @@ -291,7 +291,7 @@ class LiveScreenManager {
}

newFrame() {
console.log("capturinng new frame")
console.log("capturing new frame")
const frameData = this.captureFrameB64()
this.onNewFrame(frameData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @extends AudioWorkletProcessor
* @description Processes PCM audio data in a Web Audio API context
*/

class PCMProcessor extends AudioWorkletProcessor {
constructor() {
super();
Expand Down
31 changes: 15 additions & 16 deletions gemini/multimodal-live-api/websocket-demo-app/frontend/script.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
window.addEventListener("load", (event) => {
console.log("Hello Gemini Realtime Demo!");

setAvailableCamerasOptions();
setAvailableMicrophoneOptions();
setAvailableCamerasOptions();
setAvailableMicrophoneOptions();
});


Expand All @@ -13,8 +13,7 @@ const API_HOST = "us-central1-aiplatform.googleapis.com";

const accessTokenInput = document.getElementById("token");
const projectInput = document.getElementById("project");
const systemInstructionsInput =
document.getElementById("systemInstructions");
const systemInstructionsInput = document.getElementById("systemInstructions");

CookieJar.init("token");
CookieJar.init("project");
Expand Down Expand Up @@ -42,7 +41,7 @@ const geminiLiveApi = new GeminiLiveAPI(

geminiLiveApi.onErrorMessage = (message) => {
showDialogWithMessage(message);
setAppSatus("disconnected");
setAppStatus("disconnected");
};

function getSelectedResponseModality() {
Expand All @@ -66,13 +65,13 @@ function getSystemInstructions() {
}

function connectBtnClick() {
setAppSatus("connecting");
setAppStatus("connecting");

geminiLiveApi.responseModalities = getSelectedResponseModality();
geminiLiveApi.systemInstructions = getSystemInstructions();

geminiLiveApi.onConnectionStarted = () => {
setAppSatus("connected");
setAppStatus("connected");
startAudioInput();
};

Expand Down Expand Up @@ -188,7 +187,7 @@ function newMicSelected() {
}

function disconnectBtnClick() {
setAppSatus("disconnected");
setAppStatus("disconnected");
geminiLiveApi.disconnect();
stopAudioInput();
}
Expand All @@ -200,7 +199,7 @@ function showDialogWithMessage(messageText) {
dialog.show();
}

async function getAvalibleDevices(deviceType) {
async function getAvailableDevices(deviceType) {
const allDevices = await navigator.mediaDevices.enumerateDevices();
const devices = [];
allDevices.forEach((device) => {
Expand All @@ -214,12 +213,12 @@ async function getAvalibleDevices(deviceType) {
return devices;
}

async function getAvalibleCameras() {
return await this.getAvalibleDevices("videoinput");
async function getAvailableCameras() {
return await this.getAvailableDevices("videoinput");
}

async function getAvalibleAudioInputs() {
return await this.getAvalibleDevices("audioinput");
async function getAvailableAudioInputs() {
return await this.getAvailableDevices("audioinput");
}

function setMaterialSelect(allOptions, selectElement) {
Expand All @@ -237,18 +236,18 @@ function setMaterialSelect(allOptions, selectElement) {
}

async function setAvailableCamerasOptions() {
const cameras = await getAvalibleCameras();
const cameras = await getAvailableCameras();
const videoSelect = document.getElementById("cameraSource");
setMaterialSelect(cameras, videoSelect);
}

async function setAvailableMicrophoneOptions() {
const mics = await getAvalibleAudioInputs();
const mics = await getAvailableAudioInputs();
const audioSelect = document.getElementById("audioSource");
setMaterialSelect(mics, audioSelect);
}

function setAppSatus(status) {
function setAppStatus(status) {
disconnected.hidden = true;
connecting.hidden = true;
connected.hidden = true;
Expand Down

0 comments on commit df4623d

Please sign in to comment.