Skip to content

Commit

Permalink
Fix building of stt
Browse files Browse the repository at this point in the history
  • Loading branch information
xaionaro committed Jan 14, 2025
1 parent 51091f0 commit cbf326b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
7 changes: 3 additions & 4 deletions cmd/stt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/facebookincubator/go-belt/tool/logger"
"github.com/facebookincubator/go-belt/tool/logger/implementation/logrus"
"github.com/lazybeaver/entropy"
syswhisper "github.com/mutablelogic/go-whisper/sys/whisper"
"github.com/spf13/pflag"
"github.com/xaionaro-go/observability"
"github.com/xaionaro-go/speech/pkg/speech"
Expand All @@ -34,7 +33,7 @@ func main() {
loggerLevel := logger.LevelWarning
pflag.Var(&loggerLevel, "log-level", "Log level")
langFlag := pflag.String("language", "en-US", "")
alignmentAheadPresentFlag := types.AlignmentAheadsPreset(syswhisper.AlignmentAheadsPresetNone)
alignmentAheadPresentFlag := types.AlignmentAheadsPreset(speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetNone)
pflag.Var(&alignmentAheadPresentFlag, "alignment-aheads-preset", "")
gpuFlag := pflag.Int("gpu", -1, "")
useGPUFlag := pflag.Bool("use-gpu", true, "")
Expand Down Expand Up @@ -94,7 +93,7 @@ func main() {
Backend: &speechtotext_grpc.NewContextRequest_Whisper{
Whisper: &speechtotext_grpc.WhisperOptions{
SamplingStrategy: goconv.SamplingStrategyToGRPC(types.SamplingStrategyGreedy),
AlignmentAheadsPreset: goconv.AlignmentAheadsPresetToGRPC(syswhisper.AlignmentAheadsPreset(alignmentAheadPresentFlag)),
AlignmentAheadsPreset: speechtotext_grpc.WhisperAlignmentAheadsPreset(alignmentAheadPresentFlag),
},
},
})
Expand All @@ -106,7 +105,7 @@ func main() {
speech.Language(*langFlag),
types.SamplingStrategyGreedy,
*shouldTranslateFlag,
whisper.AlignmentAheadsPreset(alignmentAheadPresentFlag),
alignmentAheadPresentFlag,
*vadThreshold,
opts...,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package whisper

import (
"github.com/mutablelogic/go-whisper/sys/whisper"
"github.com/xaionaro-go/speech/pkg/speech/speechtotext/implementations/whisper/types"
"github.com/xaionaro-go/speech/pkg/speech/speechtotext/server/proto/go/speechtotext_grpc"
)

type AlignmentAheadsPreset types.AlignmentAheadsPreset

// String just implements fmt.Stringer, flag.Value and pflag.Value.
func (p AlignmentAheadsPreset) ToWhisper() whisper.AlignmentAheadsPreset {
switch speechtotext_grpc.WhisperAlignmentAheadsPreset(p) {
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetNone:
return whisper.AlignmentAheadsPresetNone
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetNTopMost:
return whisper.AlignmentAheadsPresetNTopMost
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetCustom:
return whisper.AlignmentAheadsPresetCustom
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetTinyEn:
return whisper.AlignmentAheadsPresetTinyEn
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetTiny:
return whisper.AlignmentAheadsPresetTiny
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetBaseEn:
return whisper.AlignmentAheadsPresetBaseEn
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetBase:
return whisper.AlignmentAheadsPresetBase
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetSmallEn:
return whisper.AlignmentAheadsPresetSmallEn
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetSmall:
return whisper.AlignmentAheadsPresetSmall
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetMediumEn:
return whisper.AlignmentAheadsPresetMediumEn
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetMedium:
return whisper.AlignmentAheadsPresetMedium
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetLargeV1:
return whisper.AlignmentAheadsPresetLargeV1
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetLargeV2:
return whisper.AlignmentAheadsPresetLargeV2
case speechtotext_grpc.WhisperAlignmentAheadsPreset_WhisperAlignmentAheadsPresetLargeV3:
return whisper.AlignmentAheadsPresetLargeV3
}
panic(p)
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func New(
params.SetFlashAttn(*cfg.FlashAttn)
}
params.SetTokenTimestamps(false)
params.SetDTWAheadsPreset(whisper.AlignmentAheadsPreset(alignmentAheadPreset))
params.SetDTWAheadsPreset(AlignmentAheadsPreset(alignmentAheadPreset).ToWhisper())
whisper.Whisper_log_set(func(level whisper.LogLevel, text string) {
logger.FromCtx(ctx).Log(logLevelFromWhisper(level), text)
})
Expand Down

0 comments on commit cbf326b

Please sign in to comment.