36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package sound
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
var speechBeepWAV = tone_wav(440, 40*time.Millisecond, 0.35, 5*time.Millisecond)
|
|
var capitalBeepWAV = nvda_tone_wav(2000, 50)
|
|
|
|
// SpeechBeep replaces an utterance, independently of role-sound enablement or
|
|
// theme availability. The speech worker owns its ordering and cancellation;
|
|
// sound preferences still supply the output sink and volume.
|
|
func (service *Service) SpeechBeep(ctx context.Context) error {
|
|
return service.play_speech_beep(ctx, speechBeepWAV)
|
|
}
|
|
|
|
// CapitalBeep is ordered and canceled by the speech worker, just like speech.
|
|
// It uses sound volume and sink, independently of the role sound theme.
|
|
func (service *Service) CapitalBeep(ctx context.Context) error {
|
|
return service.play_speech_beep(ctx, capitalBeepWAV)
|
|
}
|
|
|
|
func (service *Service) play_speech_beep(ctx context.Context, data []byte) error {
|
|
service.mutex.Lock()
|
|
player, volume := service.player, service.volume
|
|
service.mutex.Unlock()
|
|
beepContext, cancelBeep := context.WithTimeout(ctx, 3*time.Second)
|
|
defer cancelBeep()
|
|
return player.Play(beepContext, data, volume, 0)
|
|
}
|