add cancel action to pipeline to stop without transcribing
This commit is contained in:
@@ -162,6 +162,9 @@ func (d *Daemon) handle(c net.Conn) {
|
||||
case 't':
|
||||
d.toggle()
|
||||
fmt.Fprint(c, "OK toggled\n")
|
||||
case 'c':
|
||||
d.cancelPipeline()
|
||||
fmt.Fprint(c, "OK cancelled\n")
|
||||
case 's':
|
||||
status := d.status()
|
||||
fmt.Fprintf(c, "STATUS status=%s\n", status)
|
||||
@@ -191,7 +194,7 @@ func (d *Daemon) toggle() {
|
||||
go d.monitorPipelineErrors(p)
|
||||
|
||||
case pipeline.Recording:
|
||||
d.stopPipeline() // aborted during recording (chunks not sent to transcriber yet)
|
||||
d.stopPipeline()
|
||||
go d.notifier.Error("Recording Aborted")
|
||||
|
||||
case pipeline.Transcribing:
|
||||
@@ -207,11 +210,21 @@ func (d *Daemon) toggle() {
|
||||
go d.notifier.Notify("Hyprvoice", "Recording Ended... Transcribing")
|
||||
|
||||
case pipeline.Injecting:
|
||||
d.stopPipeline() // aborted during injection
|
||||
d.stopPipeline()
|
||||
go d.notifier.Error("Injection Aborted")
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Daemon) cancelPipeline() {
|
||||
switch d.status() {
|
||||
case pipeline.Idle:
|
||||
log.Printf("Daemon: Cancel requested but pipeline is idle, ignoring")
|
||||
default:
|
||||
d.stopPipeline()
|
||||
go d.notifier.Notify("Hyprvoice", "Operation Cancelled")
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Daemon) monitorPipelineErrors(p pipeline.Pipeline) {
|
||||
errorCh := p.GetErrorCh()
|
||||
for {
|
||||
|
||||
@@ -30,6 +30,7 @@ const (
|
||||
|
||||
const (
|
||||
Inject Action = "inject"
|
||||
Cancel Action = "cancel"
|
||||
)
|
||||
|
||||
type Pipeline interface {
|
||||
@@ -115,7 +116,8 @@ func (p *pipeline) run(ctx context.Context) {
|
||||
defer func() {
|
||||
if stopErr := t.Stop(ctx); stopErr != nil {
|
||||
log.Printf("Pipeline: Error stopping transcriber: %v", stopErr)
|
||||
p.sendError("Transcription Error", "Failed to stop transcriber cleanly", stopErr)
|
||||
// Silently call an error now because on simple transcriber we just transcribe all audio when we stop, and might fail when force stop
|
||||
//p.sendError("Transcription Error", "Failed to stop transcriber cleanly", stopErr)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -232,7 +234,6 @@ func (p *pipeline) handleInjectAction(ctx context.Context, recorder *recording.R
|
||||
log.Printf("Pipeline: Text injection completed successfully")
|
||||
}
|
||||
|
||||
// Return to idle state after injection is complete
|
||||
p.setStatus(Idle)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user