mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-04-28 06:49:42 +00:00
Some checks failed
Bindings Tests (Ruby) / ubuntu-22 (push) Waiting to run
CI / determine-tag (push) Waiting to run
CI / ubuntu-22 (linux/amd64) (push) Waiting to run
CI / ubuntu-22 (linux/ppc64le) (push) Waiting to run
CI / ubuntu-22-arm64 (linux/arm64) (push) Waiting to run
CI / ubuntu-22-arm-v7 (linux/arm/v7) (push) Waiting to run
CI / macOS-latest (generic/platform=iOS) (push) Waiting to run
CI / macOS-latest (generic/platform=macOS) (push) Waiting to run
CI / macOS-latest (generic/platform=tvOS) (push) Waiting to run
CI / ubuntu-22-gcc (linux/amd64, Debug) (push) Waiting to run
CI / ubuntu-22-gcc (linux/amd64, Release) (push) Waiting to run
CI / ubuntu-22-gcc (linux/ppc64le, Debug) (push) Waiting to run
CI / ubuntu-22-gcc (linux/ppc64le, Release) (push) Waiting to run
CI / ubuntu-22-gcc-arm64 (linux/arm64, Debug) (push) Waiting to run
CI / ubuntu-22-gcc-arm64 (linux/arm64, Release) (push) Waiting to run
CI / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Debug) (push) Waiting to run
CI / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Release) (push) Waiting to run
CI / ubuntu-22-clang (linux/amd64, Debug) (push) Waiting to run
CI / ubuntu-22-clang (linux/amd64, Release) (push) Waiting to run
CI / ubuntu-22-clang (linux/arm64, Debug) (push) Waiting to run
CI / ubuntu-22-clang (linux/arm64, Release) (push) Waiting to run
CI / ubuntu-22-clang (linux/ppc64le, Debug) (push) Waiting to run
CI / ubuntu-22-clang (linux/ppc64le, Release) (push) Waiting to run
CI / ubuntu-22-gcc-sanitized (linux/amd64, ADDRESS) (push) Waiting to run
CI / ubuntu-22-gcc-sanitized (linux/amd64, THREAD) (push) Waiting to run
CI / ubuntu-22-gcc-sanitized (linux/amd64, UNDEFINED) (push) Waiting to run
CI / ubuntu-22-cmake-sycl (linux/amd64, icx, icpx, ON) (push) Waiting to run
CI / ubuntu-22-cmake-sycl (linux/arm/v7, icx, icpx, ON) (push) Waiting to run
CI / ubuntu-22-cmake-sycl (linux/arm64, icx, icpx, ON) (push) Waiting to run
CI / ubuntu-22-cmake-sycl (linux/ppc64le, icx, icpx, ON) (push) Waiting to run
CI / ubuntu-22-cmake-sycl-fp16 (linux/amd64, icx, icpx, ON) (push) Waiting to run
CI / ubuntu-22-cmake-sycl-fp16 (linux/arm/v7, icx, icpx, ON) (push) Waiting to run
CI / ubuntu-22-cmake-sycl-fp16 (linux/arm64, icx, icpx, ON) (push) Waiting to run
CI / ubuntu-22-cmake-sycl-fp16 (linux/ppc64le, icx, icpx, ON) (push) Waiting to run
CI / windows-msys2 (Release, clang-x86_64, CLANG64) (push) Waiting to run
CI / windows-msys2 (Release, ucrt-x86_64, UCRT64) (push) Waiting to run
CI / windows (Win32, Release, win32-x86, x86, 2.28.5, ON) (push) Waiting to run
CI / windows (x64, Release, win32-x86-64, x64, 2.28.5, ON) (push) Waiting to run
CI / windows-blas (Win32, ON, Release, x86, 2.28.5, ON) (push) Waiting to run
CI / windows-blas (x64, ON, Release, x64, 2.28.5, ON) (push) Waiting to run
CI / windows-cublas (x64, Release, ON, 11.8.0, ON, 2.28.5) (push) Waiting to run
CI / windows-cublas (x64, Release, ON, 12.2.0, ON, 2.28.5) (push) Waiting to run
CI / emscripten (Release) (push) Waiting to run
CI / ios-xcode-build (Release) (push) Blocked by required conditions
CI / android (push) Waiting to run
CI / quantize (push) Waiting to run
CI / release (push) Blocked by required conditions
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/amd64 tag:main]) (push) Waiting to run
Bindings Tests (Go) / ubuntu-22 (push) Has been cancelled
Adding in DetectedLanguage(), a function to retrieve the detected language that's populated by processing audio. Also adding in a unit test to test the success. Co-authored-by: Amanda Der Bedrosian <aderbedrosian@sdl.com>
125 lines
2.6 KiB
Go
125 lines
2.6 KiB
Go
package whisper_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper"
|
|
"github.com/go-audio/wav"
|
|
assert "github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetLanguage(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
model, err := whisper.New(ModelPath)
|
|
assert.NoError(err)
|
|
assert.NotNil(model)
|
|
defer model.Close()
|
|
|
|
context, err := model.NewContext()
|
|
assert.NoError(err)
|
|
|
|
// This returns an error since
|
|
// the model 'models/ggml-small.en.bin'
|
|
// that is loaded is not multilingual
|
|
err = context.SetLanguage("en")
|
|
assert.Error(err)
|
|
}
|
|
|
|
func TestContextModelIsMultilingual(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
model, err := whisper.New(ModelPath)
|
|
assert.NoError(err)
|
|
assert.NotNil(model)
|
|
defer model.Close()
|
|
|
|
context, err := model.NewContext()
|
|
assert.NoError(err)
|
|
|
|
isMultilingual := context.IsMultilingual()
|
|
|
|
// This returns false since
|
|
// the model 'models/ggml-small.en.bin'
|
|
// that is loaded is not multilingual
|
|
assert.False(isMultilingual)
|
|
}
|
|
|
|
func TestLanguage(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
model, err := whisper.New(ModelPath)
|
|
assert.NoError(err)
|
|
assert.NotNil(model)
|
|
defer model.Close()
|
|
|
|
context, err := model.NewContext()
|
|
assert.NoError(err)
|
|
|
|
// This always returns en since
|
|
// the model 'models/ggml-small.en.bin'
|
|
// that is loaded is not multilingual
|
|
expectedLanguage := "en"
|
|
actualLanguage := context.Language()
|
|
assert.Equal(expectedLanguage, actualLanguage)
|
|
}
|
|
|
|
func TestProcess(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
fh, err := os.Open(SamplePath)
|
|
assert.NoError(err)
|
|
defer fh.Close()
|
|
|
|
// Decode the WAV file - load the full buffer
|
|
dec := wav.NewDecoder(fh)
|
|
buf, err := dec.FullPCMBuffer()
|
|
assert.NoError(err)
|
|
assert.Equal(uint16(1), dec.NumChans)
|
|
|
|
data := buf.AsFloat32Buffer().Data
|
|
|
|
model, err := whisper.New(ModelPath)
|
|
assert.NoError(err)
|
|
assert.NotNil(model)
|
|
defer model.Close()
|
|
|
|
context, err := model.NewContext()
|
|
assert.NoError(err)
|
|
|
|
err = context.Process(data, nil, nil, nil)
|
|
assert.NoError(err)
|
|
}
|
|
|
|
func TestDetectedLanguage(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
fh, err := os.Open(SamplePath)
|
|
assert.NoError(err)
|
|
defer fh.Close()
|
|
|
|
// Decode the WAV file - load the full buffer
|
|
dec := wav.NewDecoder(fh)
|
|
buf, err := dec.FullPCMBuffer()
|
|
assert.NoError(err)
|
|
assert.Equal(uint16(1), dec.NumChans)
|
|
|
|
data := buf.AsFloat32Buffer().Data
|
|
|
|
model, err := whisper.New(ModelPath)
|
|
assert.NoError(err)
|
|
assert.NotNil(model)
|
|
defer model.Close()
|
|
|
|
context, err := model.NewContext()
|
|
assert.NoError(err)
|
|
|
|
err = context.Process(data, nil, nil, nil)
|
|
assert.NoError(err)
|
|
|
|
expectedLanguage := "en"
|
|
actualLanguage := context.DetectedLanguage()
|
|
assert.Equal(expectedLanguage, actualLanguage)
|
|
}
|