From fcbcaeb20aa358bd0118da37abf35aa06d601c78 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 6 Jan 2026 15:53:11 +0100 Subject: [PATCH] Use byte arrays instead of base64 for .NET / JS exchange --- app/MindWork AI Studio/Layout/MainLayout.razor.cs | 5 ++--- app/MindWork AI Studio/wwwroot/app.js | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/MindWork AI Studio/Layout/MainLayout.razor.cs b/app/MindWork AI Studio/Layout/MainLayout.razor.cs index c697da54..1252e5e5 100644 --- a/app/MindWork AI Studio/Layout/MainLayout.razor.cs +++ b/app/MindWork AI Studio/Layout/MainLayout.razor.cs @@ -428,7 +428,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan } [JSInvokable] - public async Task OnAudioChunkReceived(string base64Chunk) + public async Task OnAudioChunkReceived(byte[] chunkBytes) { if (this.currentRecordingStream is null) { @@ -438,10 +438,9 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan try { - var chunkBytes = Convert.FromBase64String(base64Chunk); await this.currentRecordingStream.WriteAsync(chunkBytes); await this.currentRecordingStream.FlushAsync(); - + this.Logger.LogDebug("Wrote {ByteCount} bytes to recording stream.", chunkBytes.Length); } catch (Exception ex) diff --git a/app/MindWork AI Studio/wwwroot/app.js b/app/MindWork AI Studio/wwwroot/app.js index e183a283..8ad05422 100644 --- a/app/MindWork AI Studio/wwwroot/app.js +++ b/app/MindWork AI Studio/wwwroot/app.js @@ -93,13 +93,10 @@ window.audioRecorder = { mediaRecorder.ondataavailable = async (event) => { if (event.data.size > 0) { const arrayBuffer = await event.data.arrayBuffer(); - const base64 = btoa( - new Uint8Array(arrayBuffer).reduce((data, byte) => data + String.fromCharCode(byte), '') - ); - - // Send chunk to .NET immediately: + const uint8Array = new Uint8Array(arrayBuffer); + try { - await dotnetReference.invokeMethodAsync('OnAudioChunkReceived', base64); + await dotnetReference.invokeMethodAsync('OnAudioChunkReceived', uint8Array); } catch (error) { console.error('Error sending audio chunk to .NET:', error); }