Skip to content

Commit

Permalink
fix: player should close after stop tts
Browse files Browse the repository at this point in the history
  • Loading branch information
eeeXun committed Aug 8, 2024
1 parent 97d1708 commit 06dafb5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/gdamore/tcell/v2 v2.7.1
github.com/hajimehoshi/go-mp3 v0.3.3
github.com/hajimehoshi/oto/v2 v2.3.1
github.com/rivo/tview v0.0.0-20240519080116-fc5680eecb61
github.com/rivo/tview v0.0.0-20240807205129-e4c497cc59ed
github.com/spf13/viper v1.13.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rivo/tview v0.0.0-20240519080116-fc5680eecb61 h1:NCTByuzO45ybiCTTHlmTQx1JpsUuM62YWSP/Hg44Rdg=
github.com/rivo/tview v0.0.0-20240519080116-fc5680eecb61/go.mod h1:02iFIz7K/A9jGCvrizLPvoqr4cEIx7q54RH5Qudkrss=
github.com/rivo/tview v0.0.0-20240807205129-e4c497cc59ed h1:bd91xrd1ECzkEJ4XttUJEiyyGBHQdaOmXVEffJbAm6M=
github.com/rivo/tview v0.0.0-20240807205129-e4c497cc59ed/go.mod h1:02iFIz7K/A9jGCvrizLPvoqr4cEIx7q54RH5Qudkrss=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
Expand Down
8 changes: 2 additions & 6 deletions internal/translate/bing/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,9 @@ func (t *Translator) PlayTTS(lang, message string) error {
player.Play()
for player.IsPlaying() {
if t.IsStopped() {
return nil
return player.Close()
}
time.Sleep(time.Millisecond)
}
if err = player.Close(); err != nil {
return err
}

return nil
return player.Close()
}
8 changes: 2 additions & 6 deletions internal/translate/google/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,9 @@ func (t *Translator) PlayTTS(lang, message string) error {
player.Play()
for player.IsPlaying() {
if t.IsStopped() {
return nil
return player.Close()
}
time.Sleep(time.Millisecond)
}
if err = player.Close(); err != nil {
return err
}

return nil
return player.Close()
}
8 changes: 2 additions & 6 deletions internal/translate/reverso/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,9 @@ func (t *Translator) PlayTTS(lang, message string) error {
player.Play()
for player.IsPlaying() {
if t.IsStopped() {
return nil
return player.Close()
}
time.Sleep(time.Millisecond)
}
if err = player.Close(); err != nil {
return err
}

return nil
return player.Close()
}

0 comments on commit 06dafb5

Please sign in to comment.