mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-05 23:15:07 -06:00
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package services
|
|
|
|
import (
|
|
"github.com/Xevion/go-ha/internal/connect"
|
|
)
|
|
|
|
type TTS struct {
|
|
conn *connect.HAConnection
|
|
}
|
|
|
|
// 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)
|
|
}
|