62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"git.stormux.org/storm/fenrir/internal/config"
|
|
"git.stormux.org/storm/fenrir/internal/i18n"
|
|
"git.stormux.org/storm/fenrir/internal/speech"
|
|
)
|
|
|
|
// Reuse the current connection only when its driver, device and baud match.
|
|
// Numeric preview and restoration stay on the normal serialized speech worker.
|
|
func (ui *internalUI) test_synthesizer(ctx context.Context, selected, current config.Speech) error {
|
|
if err := ctx.Err(); err != nil {
|
|
return err
|
|
}
|
|
text := i18n.T("Voice test: The quick brown fox jumps over the lazy dog.")
|
|
sameConnection := selected.Driver == current.Driver
|
|
driver, err := speech.Find_driver(selected.Driver)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !driver.Hardware {
|
|
return fmt.Errorf("selected driver is not a hardware synthesizer")
|
|
}
|
|
if driver.Serial {
|
|
baud := func(value int) int {
|
|
if value == 0 {
|
|
return 9600
|
|
}
|
|
return value
|
|
}
|
|
sameConnection = sameConnection && selected.HardwareDevice == current.HardwareDevice && baud(selected.HardwareBaudRate) == baud(current.HardwareBaudRate)
|
|
}
|
|
if sameConnection && current.Enabled {
|
|
voice := ui.voice
|
|
if echo, ok := voice.(*echoSpeaker); ok {
|
|
voice = echo.Speaker
|
|
}
|
|
preview, ok := voice.(interface {
|
|
Say_with_parameters(string, speech.Parameters)
|
|
})
|
|
if !ok {
|
|
return fmt.Errorf("speech service does not support parameter preview")
|
|
}
|
|
preview.Say_with_parameters(text, speech.Parameters{Rate: selected.Rate, Pitch: selected.Pitch, Volume: selected.Volume})
|
|
return nil
|
|
}
|
|
return speech.Test_hardware(ctx, selected.Driver, speech_options(selected), text)
|
|
}
|
|
|
|
func (ui *internalUI) test_failed(err error) {
|
|
slog.Warn("hardware speech test failed", "error", err, "at", time.Now())
|
|
ui.voice.Say(i18n.T("Voice test failed") + ": " + err.Error())
|
|
}
|