mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 15:15:14 -06:00
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
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)
|
|
}
|