Skip to content

Commit

Permalink
With whisper, detect if the string contains a number or not if the ti…
Browse files Browse the repository at this point in the history
…mer command is used. Also don't print debug files you silly goose
  • Loading branch information
kercre123 committed Jun 27, 2024
1 parent 6d4987b commit eddce21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 9 additions & 1 deletion chipper/pkg/wirepod/speechrequest/speechrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"math"
"os"
"time"

pb "github.com/digital-dream-labs/api/go/chipperpb"
"github.com/digital-dream-labs/opus-go/opus"
Expand Down Expand Up @@ -172,6 +174,7 @@ func applyGain(samples []int16, gain float64) []int16 {

// remove noise
func highPassFilter(data []byte) []byte {
bTime := time.Now()
sampleRate := 16000
cutoffFreq := 300.0
samples, err := bytesToInt16(data)
Expand All @@ -196,7 +199,12 @@ func highPassFilter(data []byte) []byte {
int16FilteredSamples[i] = int16(sample)
}

return int16ToBytes(applyGain(int16FilteredSamples, 1.5))
gained := applyGain(int16FilteredSamples, 1.5)
if os.Getenv("DEBUG_PRINT_HIGHPASS") == "true" {
logger.Println("highpass filter took: " + fmt.Sprint(time.Since(bTime)))
}

return int16ToBytes(gained)
}

// Converts a vtt.*Request to a SpeechRequest, which allows functions like DetectEndOfSpeech to work
Expand Down
2 changes: 0 additions & 2 deletions chipper/pkg/wirepod/ttr/kgsim_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,6 @@ func DoSayText_OpenAI(robot *vector.Vector, input string) error {
},
})
}()
os.WriteFile("../../pre-process.pcm", speechBytes, 0777)
os.WriteFile("../../post-process.pcm", chunksToDetermineLength, 0777)
time.Sleep(pcmLength(chunksToDetermineLength) + (time.Millisecond * 50))
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion chipper/pkg/wirepod/ttr/words2num.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var textToNumber = map[string]int{
}

func words2num(input string) string {
if os.Getenv("STT_SERVICE") == "whisper.cpp" {
containsNum, _ := regexp.MatchString(`\b\d+\b`, input)
if os.Getenv("STT_SERVICE") == "whisper.cpp" && containsNum {
return whisperSpeechtoNum(input)
}
totalSeconds := 0
Expand Down

0 comments on commit eddce21

Please sign in to comment.