Enha: remove special tokens from whisper resp
This commit is contained in:
@@ -9,11 +9,14 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gordonklaus/portaudio"
|
"github.com/gordonklaus/portaudio"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var specialRE = regexp.MustCompile(`\[.*?\]`)
|
||||||
|
|
||||||
type STT interface {
|
type STT interface {
|
||||||
StartRecording() error
|
StartRecording() error
|
||||||
StopRecording() (string, error)
|
StopRecording() (string, error)
|
||||||
@@ -99,7 +102,9 @@ func (stt *WhisperSTT) StopRecording() (string, error) {
|
|||||||
stt.logger.Error("fn: StopRecording", "error", err)
|
stt.logger.Error("fn: StopRecording", "error", err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return strings.TrimRight(string(responseTextBytes), "\n"), nil
|
resptext := strings.TrimRight(string(responseTextBytes), "\n")
|
||||||
|
// in case there are special tokens like [_BEG_]
|
||||||
|
return specialRE.ReplaceAllString(resptext, ""), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (stt *WhisperSTT) writeWavHeader(w io.Writer, dataSize int) {
|
func (stt *WhisperSTT) writeWavHeader(w io.Writer, dataSize int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user