add tts domain/services

This commit is contained in:
jackson
2023-01-30 21:00:03 -05:00
parent abf47b223f
commit cae0c275ca
3 changed files with 58 additions and 1 deletions

View File

@@ -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
View 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)
}