Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Go api improvements #1561

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions go/example/test_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ func main() {
flag.StringVar(&filename, "f", "", "file to transcribe")
flag.Parse()

model, err := vosk.NewModel("model")
if err != nil {
log.Fatal(err)
}
vosk.SetLogLevel(vosk.Verbose)
model := vosk.NewModel("model")

// we can check if word is in the vocabulary
// fmt.Println(model.FindWord("air"))
Expand Down
14 changes: 10 additions & 4 deletions go/vosk.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type VoskModel struct {
}

// NewModel creates a new VoskModel instance
func NewModel(modelPath string) (*VoskModel, error) {
func NewModel(modelPath string) *VoskModel {
cmodelPath := C.CString(modelPath)
defer C.free(unsafe.Pointer(cmodelPath))
internal := C.vosk_model_new(cmodelPath)
model := &VoskModel{model: internal}
return model, nil
return model
}

func (m *VoskModel) Free() {
Expand Down Expand Up @@ -58,7 +58,7 @@ func freeSpkModel(model *VoskSpkModel) {
C.vosk_spk_model_free(model.spkModel)
}

func(s *VoskSpkModel) Free() {
func (s *VoskSpkModel) Free() {
C.vosk_spk_model_free(s.spkModel)
}

Expand Down Expand Up @@ -154,8 +154,14 @@ func (r *VoskRecognizer) Reset() {
C.vosk_recognizer_reset(r.rec)
}

type LogLevel int

const Disabled LogLevel = -1
const Default LogLevel = 0
const Verbose LogLevel = 1

// SetLogLevel sets the log level for Kaldi messages.
func SetLogLevel(logLevel int) {
func SetLogLevel(logLevel LogLevel) {
C.vosk_set_log_level(C.int(logLevel))
}

Expand Down