NewHTTPHandler (tts/http_handler.go)

MobileVC · internal/tts/http_handler.go · go · MIT
voice, Voice / Speech

HTTP handler for TTS synthesis and health checks with auth and error handling.

// Source: https://github.com/JayCRL/MobileVC | License: MIT | Copyright MobileVC contributors
// Provided via justclaw.it.com; keep this notice with the code.
package tts

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"strings"
	"time"

	"mobilevc/internal/logx"
)

type HTTPHandler struct {
	authToken string
	enabled   bool
	provider  string
	service   *Service
}

func NewHTTPHandler(authToken string, enabled bool, provider string, service *Service) *HTTPHandler {
	return &HTTPHandler{
		authToken: strings.TrimSpace(authToken),
		enabled:   enabled,
		provider:  strings.TrimSpace(provider),
		service:   service,
	}
}

func (h *HTTPHandler) HandleSynthesize(w http.ResponseWriter, r *http.Request) {
	if r.Method != http.MethodPost {
		http.Error(w, "method not allowed",

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key