mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-13 21:21:36 +00:00
Use byte arrays instead of base64 for .NET / JS exchange
This commit is contained in:
parent
84e2a96f49
commit
fcbcaeb20a
@ -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)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user