Fixed audio handling (#631)
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-01-18 16:01:02 +01:00
1 parent 5f18cbe2bf
commit 0a504276d9
5 files changed
+340 -131

No files matched your search

@@ -20,6 +20,18 @@ public partial class VoiceRecorder : MSGComponentBase
[Inject]
private ISnackbar Snackbar { get; init; } = null!;
#region Overrides of MSGComponentBase
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
// Initialize sound effects. This "warms up" the AudioContext and preloads all sounds for reliable playback:
await this.JsRuntime.InvokeVoidAsync("initSoundEffects");
}
#endregion
private uint numReceivedChunks;
private bool isRecording;
private bool isTranscribing;
@@ -39,6 +51,9 @@ public partial class VoiceRecorder : MSGComponentBase
{
if (toggled)
{
// Warm up sound effects:
await this.JsRuntime.InvokeVoidAsync("initSoundEffects");
var mimeTypes = GetPreferredMimeTypes(
Builder.Create().UseAudio().UseSubtype(AudioSubtype.OGG).Build(),
Builder.Create().UseAudio().UseSubtype(AudioSubtype.AAC).Build(),
@@ -189,7 +204,11 @@ public partial class VoiceRecorder : MSGComponentBase
private async Task TranscribeRecordingAsync()
{
if (this.finalRecordingPath is null)
{
// No recording to transcribe, but still release the microphone:
await this.ReleaseMicrophoneAsync();
return;
}
this.isTranscribing = true;
this.StateHasChanged();
@@ -288,12 +307,22 @@ public partial class VoiceRecorder : MSGComponentBase
}
finally
{
await this.ReleaseMicrophoneAsync();
this.finalRecordingPath = null;
this.isTranscribing = false;
this.StateHasChanged();
}
}
private async Task ReleaseMicrophoneAsync()
{
// Wait a moment for any queued sounds to finish playing, then release the microphone.
// This allows Bluetooth headsets to switch back to A2DP profile without interrupting audio:
await Task.Delay(1_800);
await this.JsRuntime.InvokeVoidAsync("audioRecorder.releaseMicrophone");
}
private sealed class AudioRecordingResult
{
public string MimeType { get; init; } = string.Empty;