feat: Add character names to scenarios and UI
Introduces `characterName` to the `Scenario` type, enabling AI personas to be explicitly named. This change also updates the `ScenarioCard` component to display the character name and adds foundational support for potential future scenario deletion functionality. The README has been updated with a new AI Studio link.
This commit is contained in:
1 parent
e92c489db5
commit
a4946ed04d
18 files changed
+3585
-320
No files matched your search
+4
-11
@@ -1,4 +1,3 @@
|
||||
import { LiveServerMessage, Modality } from "@google/genai";
|
||||
|
||||
// Convert Float32Array (Web Audio API) to PCM Int16 (Gemini API requirement)
|
||||
export function floatTo16BitPCM(float32Array: Float32Array): ArrayBuffer {
|
||||
@@ -14,10 +13,9 @@ export function floatTo16BitPCM(float32Array: Float32Array): ArrayBuffer {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Base64 encoding for the payload
|
||||
export function arrayBufferToBase64(buffer: ArrayBuffer): string {
|
||||
// Manual encoding helper as per guidelines
|
||||
export function encodeBase64(bytes: Uint8Array): string {
|
||||
let binary = '';
|
||||
const bytes = new Uint8Array(buffer);
|
||||
const len = bytes.byteLength;
|
||||
for (let i = 0; i < len; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
@@ -25,8 +23,8 @@ export function arrayBufferToBase64(buffer: ArrayBuffer): string {
|
||||
return btoa(binary);
|
||||
}
|
||||
|
||||
// Convert Base64 string back to Uint8Array
|
||||
export function base64ToUint8Array(base64: string): Uint8Array {
|
||||
// Manual decoding helper as per guidelines
|
||||
export function decodeBase64(base64: string): Uint8Array {
|
||||
const binaryString = atob(base64);
|
||||
const len = binaryString.length;
|
||||
const bytes = new Uint8Array(len);
|
||||
@@ -45,20 +43,15 @@ export async function decodeAudioData(
|
||||
): Promise<AudioBuffer> {
|
||||
// Ensure the byte length is even for Int16Array
|
||||
if (data.byteLength % 2 !== 0) {
|
||||
console.warn("Received odd byte length for PCM16 audio, trimming last byte.");
|
||||
data = data.subarray(0, data.byteLength - 1);
|
||||
}
|
||||
|
||||
// Use the underlying buffer, but handle offsets if the Uint8Array is a view
|
||||
const dataInt16 = new Int16Array(data.buffer, data.byteOffset, data.byteLength / 2);
|
||||
|
||||
const buffer = ctx.createBuffer(numChannels, dataInt16.length / numChannels, sampleRate);
|
||||
|
||||
for (let channel = 0; channel < numChannels; channel++) {
|
||||
const channelData = buffer.getChannelData(channel);
|
||||
// Determine step size if multiple channels (usually 1 for this API)
|
||||
for (let i = 0; i < dataInt16.length; i++) {
|
||||
// Normalize Int16 to Float32 [-1.0, 1.0]
|
||||
channelData[i] = dataInt16[i] / 32768.0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user