mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-03 15:36:29 +08:00
Change wyoming Event.Data type to string
This commit is contained in:
@@ -64,10 +64,11 @@ func (w *API) ReadEvent() (*Event, error) {
|
|||||||
evt := Event{Type: hdr.Type}
|
evt := Event{Type: hdr.Type}
|
||||||
|
|
||||||
if hdr.DataLength > 0 {
|
if hdr.DataLength > 0 {
|
||||||
evt.Data = make([]byte, hdr.DataLength)
|
data = make([]byte, hdr.DataLength)
|
||||||
if _, err = io.ReadFull(w.rd, evt.Data); err != nil {
|
if _, err = io.ReadFull(w.rd, data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
evt.Data = string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hdr.PayloadLength > 0 {
|
if hdr.PayloadLength > 0 {
|
||||||
@@ -86,7 +87,7 @@ func (w *API) Close() error {
|
|||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Type string
|
Type string
|
||||||
Data []byte
|
Data string
|
||||||
Payload []byte
|
Payload []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,7 +44,7 @@ func (b *Backchannel) AddTrack(media *core.Media, codec *core.Codec, track *core
|
|||||||
ts := time.Now().Nanosecond()
|
ts := time.Now().Nanosecond()
|
||||||
evt := &Event{
|
evt := &Event{
|
||||||
Type: "audio-chunk",
|
Type: "audio-chunk",
|
||||||
Data: []byte(fmt.Sprintf(`{"rate":22050,"width":2,"channels":1,"timestamp":%d}`, ts)),
|
Data: fmt.Sprintf(`{"rate":22050,"width":2,"channels":1,"timestamp":%d}`, ts),
|
||||||
Payload: pkt.Payload,
|
Payload: pkt.Payload,
|
||||||
}
|
}
|
||||||
_ = b.api.WriteEvent(evt)
|
_ = b.api.WriteEvent(evt)
|
||||||
|
@@ -16,7 +16,7 @@ func (s *Server) HandleMic(conn net.Conn) error {
|
|||||||
api := NewAPI(conn)
|
api := NewAPI(conn)
|
||||||
mic := newMicConsumer(func(chunk []byte) {
|
mic := newMicConsumer(func(chunk []byte) {
|
||||||
data := fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, timestamp)
|
data := fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, timestamp)
|
||||||
evt := &Event{Type: "audio-chunk", Data: []byte(data), Payload: chunk}
|
evt := &Event{Type: "audio-chunk", Data: data, Payload: chunk}
|
||||||
if err := api.WriteEvent(evt); err != nil {
|
if err := api.WriteEvent(evt); err != nil {
|
||||||
closed.Done(nil)
|
closed.Done(nil)
|
||||||
}
|
}
|
||||||
|
@@ -57,7 +57,7 @@ func (s *Server) Handle(conn net.Conn) error {
|
|||||||
case "describe":
|
case "describe":
|
||||||
// {"asr": [], "tts": [], "handle": [], "intent": [], "wake": [], "satellite": {"name": "my satellite", "attribution": {"name": "", "url": ""}, "installed": true, "description": "my satellite", "version": "1.4.1", "area": null, "snd_format": null}}
|
// {"asr": [], "tts": [], "handle": [], "intent": [], "wake": [], "satellite": {"name": "my satellite", "attribution": {"name": "", "url": ""}, "installed": true, "description": "my satellite", "version": "1.4.1", "area": null, "snd_format": null}}
|
||||||
data := fmt.Sprintf(`{"satellite":{"name":%q,"attribution":{"name":"go2rtc","url":"https://github.com/AlexxIT/go2rtc"},"installed":true}}`, s.Name)
|
data := fmt.Sprintf(`{"satellite":{"name":%q,"attribution":{"name":"go2rtc","url":"https://github.com/AlexxIT/go2rtc"},"installed":true}}`, s.Name)
|
||||||
_ = api.WriteEvent(&Event{Type: "info", Data: []byte(data)})
|
_ = api.WriteEvent(&Event{Type: "info", Data: data})
|
||||||
case "run-satellite":
|
case "run-satellite":
|
||||||
if err = sat.run(); err != nil {
|
if err = sat.run(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -193,7 +193,7 @@ func (s *satellite) onMicChunk(chunk []byte) {
|
|||||||
// some problems with wake word - redirect to HA
|
// some problems with wake word - redirect to HA
|
||||||
evt := &Event{
|
evt := &Event{
|
||||||
Type: "run-pipeline",
|
Type: "run-pipeline",
|
||||||
Data: []byte(`{"start_stage":"wake","end_stage":"tts","restart_on_end":false}`),
|
Data: `{"start_stage":"wake","end_stage":"tts","restart_on_end":false}`,
|
||||||
}
|
}
|
||||||
if err := s.api.WriteEvent(evt); err != nil {
|
if err := s.api.WriteEvent(evt); err != nil {
|
||||||
return
|
return
|
||||||
@@ -211,7 +211,7 @@ func (s *satellite) onMicChunk(chunk []byte) {
|
|||||||
// check if wake word detected
|
// check if wake word detected
|
||||||
evt := &Event{
|
evt := &Event{
|
||||||
Type: "run-pipeline",
|
Type: "run-pipeline",
|
||||||
Data: []byte(`{"start_stage":"asr","end_stage":"tts","restart_on_end":false}`),
|
Data: `{"start_stage":"asr","end_stage":"tts","restart_on_end":false}`,
|
||||||
}
|
}
|
||||||
_ = s.api.WriteEvent(evt)
|
_ = s.api.WriteEvent(evt)
|
||||||
s.state = stateStreaming
|
s.state = stateStreaming
|
||||||
@@ -232,7 +232,7 @@ func (s *satellite) onMicChunk(chunk []byte) {
|
|||||||
|
|
||||||
if s.state == stateStreaming {
|
if s.state == stateStreaming {
|
||||||
data := fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, s.timestamp)
|
data := fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, s.timestamp)
|
||||||
evt := &Event{Type: "audio-chunk", Data: []byte(data), Payload: chunk}
|
evt := &Event{Type: "audio-chunk", Data: data, Payload: chunk}
|
||||||
_ = s.api.WriteEvent(evt)
|
_ = s.api.WriteEvent(evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ func (w *WakeWord) handle() {
|
|||||||
var data struct {
|
var data struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(evt.Data, &data); err != nil {
|
if err = json.Unmarshal([]byte(evt.Data), &data); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Detection = data.Name
|
w.Detection = data.Name
|
||||||
@@ -95,7 +95,7 @@ func (w *WakeWord) Start() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
evt := &Event{Type: "detect", Data: data}
|
evt := &Event{Type: "detect", Data: string(data)}
|
||||||
if err := w.WriteEvent(evt); err != nil {
|
if err := w.WriteEvent(evt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ func (w *WakeWord) WriteChunk(payload []byte) error {
|
|||||||
return w.WriteEvent(evt)
|
return w.WriteEvent(evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func audioData(send int) []byte {
|
func audioData(send int) string {
|
||||||
// timestamp in ms = send / 2 * 1000 / 16000 = send / 32
|
// timestamp in ms = send / 2 * 1000 / 16000 = send / 32
|
||||||
return []byte(fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, send/32))
|
return fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, send/32)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user