block while tts speaking for singleton
parent
43566be7ae
commit
8fd0067ad1
|
|
@ -7,6 +7,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/faiface/beep"
|
||||
|
|
@ -15,6 +16,10 @@ import (
|
|||
"github.com/faiface/beep/wav"
|
||||
)
|
||||
|
||||
var (
|
||||
ttsLock = &sync.RWMutex{}
|
||||
)
|
||||
|
||||
func (v01 *V01) tts(text string) {
|
||||
if err := v01._tts(text); err != nil {
|
||||
log.Printf("failed to tts: %s: %v", text, err)
|
||||
|
|
@ -58,7 +63,11 @@ func (v01 *V01) _tts(text string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ttsLock.Lock()
|
||||
defer ttsLock.Unlock()
|
||||
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/30))
|
||||
speaker.Play(&effects.Volume{Streamer: beep.ResampleRatio(4, 1, &beep.Ctrl{Streamer: beep.Loop(1, decoder)})})
|
||||
duration := time.Duration(decoder.Len()) * format.SampleRate.D(1)
|
||||
time.Sleep(duration)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ func TestV01Feedback(t *testing.T) {
|
|||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
time.Sleep(time.Second * 2)
|
||||
time.Sleep(time.Second * 3)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue