Scaffold modules and queue layer
This commit is contained in:
parent
a7b0d1440d
commit
2850843294
6
internal/routing/plugin/plugin.go
Normal file
6
internal/routing/plugin/plugin.go
Normal file
@ -0,0 +1,6 @@
|
||||
package plugin
|
||||
|
||||
type Metadata struct {
|
||||
Name string
|
||||
Description string
|
||||
}
|
||||
58
internal/routing/queue/queue.go
Normal file
58
internal/routing/queue/queue.go
Normal file
@ -0,0 +1,58 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Task func(context.Context) error
|
||||
|
||||
type Queue struct {
|
||||
mu sync.Mutex
|
||||
closed bool
|
||||
ch chan Task
|
||||
}
|
||||
|
||||
func New(size int) *Queue {
|
||||
if size < 1 {
|
||||
size = 1
|
||||
}
|
||||
return &Queue{ch: make(chan Task, size)}
|
||||
}
|
||||
|
||||
func (q *Queue) Start(ctx context.Context) {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case task, ok := <-q.ch:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if task != nil {
|
||||
_ = task(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queue) Enqueue(task Task) bool {
|
||||
q.mu.Lock()
|
||||
defer q.mu.Unlock()
|
||||
if q.closed {
|
||||
return false
|
||||
}
|
||||
q.ch <- task
|
||||
return true
|
||||
}
|
||||
|
||||
func (q *Queue) Close() {
|
||||
q.mu.Lock()
|
||||
if q.closed {
|
||||
q.mu.Unlock()
|
||||
return
|
||||
}
|
||||
q.closed = true
|
||||
close(q.ch)
|
||||
q.mu.Unlock()
|
||||
}
|
||||
8
internal/session/session.go
Normal file
8
internal/session/session.go
Normal file
@ -0,0 +1,8 @@
|
||||
package session
|
||||
|
||||
type ID string
|
||||
|
||||
type Context struct {
|
||||
SessionKey string
|
||||
RunID string
|
||||
}
|
||||
6
modules/audio/audio.go
Normal file
6
modules/audio/audio.go
Normal file
@ -0,0 +1,6 @@
|
||||
package audio
|
||||
|
||||
type Device struct {
|
||||
Name string
|
||||
ID string
|
||||
}
|
||||
6
modules/stt/stt.go
Normal file
6
modules/stt/stt.go
Normal file
@ -0,0 +1,6 @@
|
||||
package stt
|
||||
|
||||
type Transcript struct {
|
||||
Text string
|
||||
Source string
|
||||
}
|
||||
8
modules/tts/tts.go
Normal file
8
modules/tts/tts.go
Normal file
@ -0,0 +1,8 @@
|
||||
package tts
|
||||
|
||||
type Request struct {
|
||||
Text string
|
||||
Voice string
|
||||
Rate int
|
||||
Engine string
|
||||
}
|
||||
5
modules/wakeword/wakeword.go
Normal file
5
modules/wakeword/wakeword.go
Normal file
@ -0,0 +1,5 @@
|
||||
package wakeword
|
||||
|
||||
type Event struct {
|
||||
Keyword string
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user