Add Go API for speech enhancement GTCRN models (#1991)
This commit is contained in:
4
go-api-examples/speech-enhancement-gtcrn/go.mod
Normal file
4
go-api-examples/speech-enhancement-gtcrn/go.mod
Normal file
@@ -0,0 +1,4 @@
|
||||
module speech-enhancement-gtcrn
|
||||
|
||||
go 1.17
|
||||
|
||||
43
go-api-examples/speech-enhancement-gtcrn/main.go
Normal file
43
go-api-examples/speech-enhancement-gtcrn/main.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
sherpa "github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
|
||||
|
||||
config := sherpa.OfflineSpeechDenoiserConfig{}
|
||||
|
||||
// Please download the models from
|
||||
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/speech-enhancement-models
|
||||
|
||||
config.Model.Gtcrn.Model = "./gtcrn_simple.onnx"
|
||||
config.Model.NumThreads = 1
|
||||
config.Model.Debug = 1
|
||||
|
||||
sd := sherpa.NewOfflineSpeechDenoiser(&config)
|
||||
defer sherpa.DeleteOfflineSpeechDenoiser(sd)
|
||||
|
||||
wave_filename := "./inp_16k.wav"
|
||||
|
||||
wave := sherpa.ReadWave(wave_filename)
|
||||
if wave == nil {
|
||||
log.Printf("Failed to read %v\n", wave_filename)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Started")
|
||||
audio := sd.Run(wave.Samples, wave.SampleRate)
|
||||
log.Println("Done!")
|
||||
|
||||
filename := "./enhanced-16k.wav"
|
||||
ok := audio.Save(filename)
|
||||
if !ok {
|
||||
log.Fatalf("Failed to write", filename)
|
||||
} else {
|
||||
log.Println("Saved to ", filename)
|
||||
}
|
||||
|
||||
}
|
||||
15
go-api-examples/speech-enhancement-gtcrn/run.sh
Executable file
15
go-api-examples/speech-enhancement-gtcrn/run.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
if [ ! -f ./gtcrn_simple.onnx ]; then
|
||||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/speech-enhancement-models/gtcrn_simple.onnx
|
||||
fi
|
||||
|
||||
if [ ! -f ./inp_16k.wav ]; then
|
||||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/speech-enhancement-models/inp_16k.wav
|
||||
fi
|
||||
|
||||
go mod tidy
|
||||
go build
|
||||
|
||||
./speech-enhancement-gtcrn
|
||||
Reference in New Issue
Block a user