docs: update README with detailed desktop features and setup requirements
This commit is contained in:
@@ -27,14 +27,27 @@ type Processor struct {
|
||||
nextPreviewAt int
|
||||
previewReceived int
|
||||
totalSamples int
|
||||
activity Activity
|
||||
speechKnown bool
|
||||
speechActive bool
|
||||
}
|
||||
|
||||
type Activity struct {
|
||||
SpeechChanged func(bool)
|
||||
RecognitionChanged func(bool)
|
||||
}
|
||||
|
||||
func New(settings config.Settings, transcriber Transcriber, emit func(Event) error) *Processor {
|
||||
return NewWithActivity(settings, transcriber, emit, Activity{})
|
||||
}
|
||||
|
||||
func NewWithActivity(settings config.Settings, transcriber Transcriber, emit func(Event) error, activity Activity) *Processor {
|
||||
return &Processor{
|
||||
settings: settings,
|
||||
transcriber: transcriber,
|
||||
emit: emit,
|
||||
nextPreviewAt: audio.DurationSamples(settings.ChunkDuration),
|
||||
activity: activity,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +56,7 @@ func (p *Processor) Accept(samples []float32) error {
|
||||
return nil
|
||||
}
|
||||
if p.settings.Mode == config.ModeFixed {
|
||||
p.setSpeechActive(audio.RMSDBFS(samples) >= p.settings.PreviewThresholdDB)
|
||||
return p.acceptFixed(samples)
|
||||
}
|
||||
return p.acceptVAD(samples)
|
||||
@@ -84,6 +98,7 @@ func (p *Processor) acceptVAD(samples []float32) error {
|
||||
p.transcriber.AcceptVAD(samples)
|
||||
|
||||
speechActive := p.transcriber.SpeechActive()
|
||||
p.setSpeechActive(speechActive)
|
||||
if speechActive && (p.previewActive || audio.RMSDBFS(samples) >= p.settings.PreviewThresholdDB) {
|
||||
if !p.previewActive {
|
||||
p.previewActive = true
|
||||
@@ -144,7 +159,7 @@ func (p *Processor) resetPreview() {
|
||||
}
|
||||
|
||||
func (p *Processor) emitProvisional() error {
|
||||
text := strings.TrimSpace(p.transcriber.Decode(p.previewSamples))
|
||||
text := strings.TrimSpace(p.decode(p.previewSamples))
|
||||
if text == "" {
|
||||
return nil
|
||||
}
|
||||
@@ -157,7 +172,7 @@ func (p *Processor) emitProvisional() error {
|
||||
}
|
||||
|
||||
func (p *Processor) emitFinal(start, end int, samples []float32) error {
|
||||
text := strings.TrimSpace(p.transcriber.Decode(samples))
|
||||
text := strings.TrimSpace(p.decode(samples))
|
||||
if text == "" {
|
||||
return p.emit(Event{Kind: Hide})
|
||||
}
|
||||
@@ -169,6 +184,25 @@ func (p *Processor) emitFinal(start, end int, samples []float32) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Processor) decode(samples []float32) string {
|
||||
if p.activity.RecognitionChanged != nil {
|
||||
p.activity.RecognitionChanged(true)
|
||||
defer p.activity.RecognitionChanged(false)
|
||||
}
|
||||
return p.transcriber.Decode(samples)
|
||||
}
|
||||
|
||||
func (p *Processor) setSpeechActive(active bool) {
|
||||
if p.speechKnown && p.speechActive == active {
|
||||
return
|
||||
}
|
||||
p.speechKnown = true
|
||||
p.speechActive = active
|
||||
if p.activity.SpeechChanged != nil {
|
||||
p.activity.SpeechChanged(active)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Processor) emitFixedFinal(start, end int, samples []float32) error {
|
||||
if audio.RMSDBFS(samples) < p.settings.PreviewThresholdDB {
|
||||
return p.emit(Event{Kind: Hide})
|
||||
|
||||
Reference in New Issue
Block a user