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