mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-05 23:15:07 -06:00
Additionally, removed the context that gets passed into the Services but isn't used in one of them. The websockets APIs also don't have any use for context.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package services
|
|
|
|
import (
|
|
ws "saml.dev/gome-assistant/internal/websocket"
|
|
)
|
|
|
|
/* Structs */
|
|
|
|
type TTS struct {
|
|
conn *ws.WebsocketWriter
|
|
}
|
|
|
|
/* Public API */
|
|
|
|
// Remove all text-to-speech cache files and RAM cache.
|
|
func (tts TTS) ClearCache() error {
|
|
req := NewBaseServiceRequest("")
|
|
req.Domain = "tts"
|
|
req.Service = "clear_cache"
|
|
|
|
return tts.conn.WriteMessage(req)
|
|
}
|
|
|
|
// 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 (tts TTS) CloudSay(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "tts"
|
|
req.Service = "cloud_say"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return tts.conn.WriteMessage(req)
|
|
}
|
|
|
|
// 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 (tts TTS) GoogleTranslateSay(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "tts"
|
|
req.Service = "google_translate_say"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return tts.conn.WriteMessage(req)
|
|
}
|