Fix: supressed alsa warnings

This commit is contained in:
Grail Finder
2025-11-12 12:20:55 +03:00
parent e1b260c474
commit 2695cf437e
2 changed files with 50 additions and 47 deletions

View File

@@ -12,6 +12,7 @@ import (
"net/http"
"regexp"
"strings"
"syscall"
"github.com/gordonklaus/portaudio"
)
@@ -145,6 +146,21 @@ func (stt *WhisperServer) IsRecording() bool {
}
func (stt *WhisperServer) microphoneStream(sampleRate int) error {
// Temporarily redirect stderr to suppress ALSA warnings during PortAudio init
origStderr, err := syscall.Dup(syscall.Stderr)
nullFD, err := syscall.Open("/dev/null", syscall.O_WRONLY, 0)
if err != nil {
return fmt.Errorf("failed to open /dev/null: %w", err)
}
// redirect stderr
syscall.Dup2(nullFD, syscall.Stderr)
// Initialize PortAudio (this is where ALSA warnings occur)
defer func() {
// Restore stderr
syscall.Dup2(origStderr, syscall.Stderr)
syscall.Close(origStderr)
syscall.Close(nullFD)
}()
if err := portaudio.Initialize(); err != nil {
return fmt.Errorf("portaudio init failed: %w", err)
}