mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 03:15:14 -06:00
add tts domain/services
This commit is contained in:
@@ -23,7 +23,8 @@ func BuildService[
|
||||
InputNumber |
|
||||
Notify |
|
||||
Number |
|
||||
Scene,
|
||||
Scene |
|
||||
TTS,
|
||||
](conn *websocket.Conn, ctx context.Context) *T {
|
||||
return &T{conn: conn, ctx: ctx}
|
||||
}
|
||||
|
||||
54
internal/services/tts.go
Normal file
54
internal/services/tts.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
ws "saml.dev/gome-assistant/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
type TTS struct {
|
||||
conn *websocket.Conn
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
|
||||
// Remove all text-to-speech cache files and RAM cache.
|
||||
func (tts TTS) ClearCache() {
|
||||
req := NewBaseServiceRequest("")
|
||||
req.Domain = "tts"
|
||||
req.Service = "clear_cache"
|
||||
|
||||
ws.WriteMessage(req, tts.conn, tts.ctx)
|
||||
}
|
||||
|
||||
// Say something using text-to-speech on a media player with cloud.
|
||||
// Takes an entityId and an optional
|
||||
// map that is translated into service_data.
|
||||
func (mp MediaPlayer) CloudSay(entityId string, serviceData ...map[string]any) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "tts"
|
||||
req.Service = "cloud_say"
|
||||
if len(serviceData) != 0 {
|
||||
req.ServiceData = serviceData[0]
|
||||
}
|
||||
|
||||
ws.WriteMessage(req, mp.conn, mp.ctx)
|
||||
}
|
||||
|
||||
// Say something using text-to-speech on a media player with google_translate.
|
||||
// Takes an entityId and an optional
|
||||
// map that is translated into service_data.
|
||||
func (mp MediaPlayer) GoogleTranslateSay(entityId string, serviceData ...map[string]any) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "tts"
|
||||
req.Service = "google_translate_say"
|
||||
if len(serviceData) != 0 {
|
||||
req.ServiceData = serviceData[0]
|
||||
}
|
||||
|
||||
ws.WriteMessage(req, mp.conn, mp.ctx)
|
||||
}
|
||||
@@ -24,6 +24,7 @@ type Service struct {
|
||||
Notify *services.Notify
|
||||
Number *services.Number
|
||||
Scene *services.Scene
|
||||
TTS *services.TTS
|
||||
}
|
||||
|
||||
func newService(conn *websocket.Conn, ctx context.Context, httpClient *http.HttpClient) *Service {
|
||||
@@ -43,5 +44,6 @@ func newService(conn *websocket.Conn, ctx context.Context, httpClient *http.Http
|
||||
Notify: services.BuildService[services.Notify](conn, ctx),
|
||||
Number: services.BuildService[services.Number](conn, ctx),
|
||||
Scene: services.BuildService[services.Scene](conn, ctx),
|
||||
TTS: services.BuildService[services.TTS](conn, ctx),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user