mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-13 23: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]
|
[JSInvokable]
|
||||||
public async Task OnAudioChunkReceived(string base64Chunk)
|
public async Task OnAudioChunkReceived(byte[] chunkBytes)
|
||||||
{
|
{
|
||||||
if (this.currentRecordingStream is null)
|
if (this.currentRecordingStream is null)
|
||||||
{
|
{
|
||||||
@ -438,10 +438,9 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var chunkBytes = Convert.FromBase64String(base64Chunk);
|
|
||||||
await this.currentRecordingStream.WriteAsync(chunkBytes);
|
await this.currentRecordingStream.WriteAsync(chunkBytes);
|
||||||
await this.currentRecordingStream.FlushAsync();
|
await this.currentRecordingStream.FlushAsync();
|
||||||
|
|
||||||
this.Logger.LogDebug("Wrote {ByteCount} bytes to recording stream.", chunkBytes.Length);
|
this.Logger.LogDebug("Wrote {ByteCount} bytes to recording stream.", chunkBytes.Length);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@ -93,13 +93,10 @@ window.audioRecorder = {
|
|||||||
mediaRecorder.ondataavailable = async (event) => {
|
mediaRecorder.ondataavailable = async (event) => {
|
||||||
if (event.data.size > 0) {
|
if (event.data.size > 0) {
|
||||||
const arrayBuffer = await event.data.arrayBuffer();
|
const arrayBuffer = await event.data.arrayBuffer();
|
||||||
const base64 = btoa(
|
const uint8Array = new Uint8Array(arrayBuffer);
|
||||||
new Uint8Array(arrayBuffer).reduce((data, byte) => data + String.fromCharCode(byte), '')
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send chunk to .NET immediately:
|
|
||||||
try {
|
try {
|
||||||
await dotnetReference.invokeMethodAsync('OnAudioChunkReceived', base64);
|
await dotnetReference.invokeMethodAsync('OnAudioChunkReceived', uint8Array);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error sending audio chunk to .NET:', error);
|
console.error('Error sending audio chunk to .NET:', error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user