Make Piper's synthesis path configurable (TTS_PATH)
piper-tts 1.6.0 moved synthesis from POST / to POST /synthesize, with an identical request body; the VPS sidecars run 1.6.0 and returned 405 to every read-aloud request, while millenia's older server still expects /. Rather than pinning both deployments to one Piper release, the path is configuration -- default "/" keeps millenia working untouched, and the compose stack sets /synthesize. The container healthcheck moves with it, since it was probing the old route too.
This commit is contained in:
@@ -36,12 +36,56 @@ func newHandler(t *testing.T, endpoint string) *Handler {
|
||||
t.Helper()
|
||||
return &Handler{
|
||||
routes: map[string]route{"en": {strings.TrimRight(endpoint, "/"), "en_US-amy-medium"}},
|
||||
synthURI: synthPath("/"),
|
||||
cacheDir: t.TempDir(),
|
||||
format: formats["wav"],
|
||||
client: http.DefaultClient,
|
||||
}
|
||||
}
|
||||
|
||||
// Piper 1.6.0 serves synthesis on /synthesize and 405s on /. The path is
|
||||
// configuration (TTS_PATH) so one Petal build talks to either server version;
|
||||
// this asserts the configured path is the one actually requested.
|
||||
func TestSynthUsesConfiguredPath(t *testing.T) {
|
||||
var gotPath string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotPath = r.URL.Path
|
||||
if r.URL.Path != "/synthesize" {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "audio/wav")
|
||||
_, _ = w.Write([]byte("RIFF....fake-wav"))
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
h := newHandler(t, srv.URL)
|
||||
h.synthURI = synthPath("/synthesize")
|
||||
|
||||
if rr := post(t, h, "hello there", "en-US"); rr.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200 (piper saw path %q)", rr.Code, gotPath)
|
||||
}
|
||||
if gotPath != "/synthesize" {
|
||||
t.Errorf("piper path = %q, want /synthesize", gotPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSynthPathNormalisation(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"": "/",
|
||||
"/": "/",
|
||||
"synthesize": "/synthesize",
|
||||
"/synthesize": "/synthesize",
|
||||
"/synthesize/": "/synthesize",
|
||||
" /v1/tts ": "/v1/tts",
|
||||
}
|
||||
for in, want := range cases {
|
||||
if got := synthPath(in); got != want {
|
||||
t.Errorf("synthPath(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func post(t *testing.T, h *Handler, text, lang string) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
b, _ := json.Marshal(synthRequest{Text: text, Lang: lang})
|
||||
|
||||
Reference in New Issue
Block a user