9 Commits
v0.1 ... 0.1.2

Author SHA1 Message Date
dde206facd Merge pull request #1 from lukaskwkw/chore/update-readme-build
Add pre build step
2024-03-11 11:18:20 +01:00
2e92dd91cb Add pre build step 2024-03-11 11:06:16 +01:00
dacad9a4f6 add method to set source language 2023-10-07 22:20:26 +03:00
7d6be4b7d3 remove unnecessary flags 2023-10-07 22:19:51 +03:00
7b0797cca1 update readme 2023-10-05 23:49:15 +03:00
482616fb4c Ensure the existence of the temp directory in the binary root 2023-10-05 23:42:04 +03:00
b36fe91b5c enable cors 2023-10-05 23:31:16 +03:00
4078a17240 update readme 2023-10-05 23:29:43 +03:00
aa93d79b38 update readme 2023-10-05 23:13:18 +03:00
7 changed files with 73 additions and 8 deletions

View File

@ -6,10 +6,31 @@ This API server enables audio transcription using the OpenAI Whisper models.
# Setup # Setup
- Download the desired model from [huggingface](https://huggingface.co/ggerganov/whisper.cpp/tree/main) - Download `.exe` from [Releases](https://github.com/xzeldon/whisper-api-server/releases/latest)
- Update the model path in the `main.go` file - Just run it!
- Download `Whisper.dll` from [github](https://github.com/Const-me/Whisper/releases/tag/1.12.0) (`Library.zip`) and place it in the project's root directory
- Build project: `go build .` (you only need go compiler, without gcc) # Build from source
Before build make sure that **CGO_ENABLED** env is set to **1**
```
set CGO_ENABLED 1
```
or preferable set it parament. Then check it via
```
go env
```
Also you have to have installed gcc x64 i.e. by MYSYS
Download the sources and use `go build`.
For example, you can build using the following command:
```bash
go build -ldflags "-s -w" -o server.exe main.go
```
# Usage example # Usage example
@ -29,12 +50,24 @@ Receive a response in JSON format:
} }
``` ```
# Usage with [Obsidian](https://obsidian.md/)
1. Install [Obsidian voice recognotion plugin](https://github.com/nikdanilov/whisper-obsidian-plugin)
2. Open the plugin's settings.
3. Set the following values:
- API KEY: `sk-1`
- API URL: `http://localhost:3000/v1/audio/transcriptions`
- Model: `whisper-1`
# Roadmap # Roadmap
- [x] Implement automatic model downloading from [huggingface](https://huggingface.co/ggerganov/whisper.cpp/tree/main) - [x] Implement automatic model downloading from [huggingface](https://huggingface.co/ggerganov/whisper.cpp/tree/main)
- [x] Implement automatic `Whisper.dll` downloading from [Guthub releases](https://github.com/Const-me/Whisper/releases) - [x] Implement automatic `Whisper.dll` downloading from [Guthub releases](https://github.com/Const-me/Whisper/releases)
- [x] Provide prebuilt binaries for Windows - [x] Provide prebuilt binaries for Windows
- [ ] Include instructions for running on Linux with Wine (likely possible). - [ ] Include instructions for running on Linux with Wine (likely possible).
- [ ] Use flags to override the model path
- [ ] Use flags to override the model type (when downloading the model)
- [ ] Use flags to override the port
# Credits # Credits

2
go.mod
View File

@ -9,10 +9,12 @@ require (
) )
require ( require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.2.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/term v0.10.0 // indirect golang.org/x/term v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
) )
require ( require (

4
go.sum
View File

@ -1,6 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/labstack/echo/v4 v4.11.1 h1:dEpLU2FLg4UVmvCGPuk/APjlH6GDpbEPti61srUUUs4= github.com/labstack/echo/v4 v4.11.1 h1:dEpLU2FLg4UVmvCGPuk/APjlH6GDpbEPti61srUUUs4=
github.com/labstack/echo/v4 v4.11.1/go.mod h1:YuYRTSM3CHs2ybfrL8Px48bO6BAnYIN4l8wSTMP6BDQ= github.com/labstack/echo/v4 v4.11.1/go.mod h1:YuYRTSM3CHs2ybfrL8Px48bO6BAnYIN4l8wSTMP6BDQ=
@ -50,6 +52,8 @@ golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -41,9 +41,6 @@ func InitializeWhisperState(modelPath string) (*WhisperState, error) {
return nil, err return nil, err
} }
params.AddFlags(whisper.FlagNoContext)
params.AddFlags(whisper.FlagTokenTimestamps)
fmt.Printf("Params CPU Threads : %d\n", params.CpuThreads()) fmt.Printf("Params CPU Threads : %d\n", params.CpuThreads())
return &WhisperState{ return &WhisperState{

View File

@ -22,9 +22,14 @@ func saveFormFile(name string, c echo.Context) (string, error) {
} }
defer src.Close() defer src.Close()
tmpDir, err := ensureDir("tmp")
if err != nil {
return "", err
}
ext := filepath.Ext(file.Filename) ext := filepath.Ext(file.Filename)
filename := time.Now().Format(time.RFC3339) filename := time.Now().Format(time.RFC3339)
filename = "./tmp/" + sanitizeFilename(filename) + ext filename = tmpDir + "/" + sanitizeFilename(filename) + ext
dst, err := os.Create(filename) dst, err := os.Create(filename)
if err != nil { if err != nil {
@ -46,3 +51,14 @@ func sanitizeFilename(filename string) string {
} }
return filename return filename
} }
func ensureDir(dirPath string) (string, error) {
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
err := os.MkdirAll(dirPath, 0700)
if err != nil {
return "", err
}
}
return dirPath, nil
}

View File

@ -2,6 +2,7 @@ package main
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log" "github.com/labstack/gommon/log"
"github.com/xzeldon/whisper-api-server/internal/api" "github.com/xzeldon/whisper-api-server/internal/api"
"github.com/xzeldon/whisper-api-server/internal/resources" "github.com/xzeldon/whisper-api-server/internal/resources"
@ -11,6 +12,8 @@ func main() {
e := echo.New() e := echo.New()
e.HideBanner = true e.HideBanner = true
e.Use(middleware.CORS())
if l, ok := e.Logger.(*log.Logger); ok { if l, ok := e.Logger.(*log.Logger); ok {
l.SetHeader("${time_rfc3339} ${level}") l.SetHeader("${time_rfc3339} ${level}")
} }

View File

@ -86,6 +86,16 @@ func (this *FullParams) RemoveFlags(newflag eFullParamsFlags) {
this.cStruct.Flags = this.cStruct.Flags ^ newflag this.cStruct.Flags = this.cStruct.Flags ^ newflag
} }
func (this *FullParams) SetLanguage(language eLanguage) {
if this == nil {
return
} else if this.cStruct == nil {
return
}
this.cStruct.Language = language
}
/*using pfnNewSegment = HRESULT( __cdecl* )( iContext* ctx, uint32_t n_new, void* user_data ) noexcept;*/ /*using pfnNewSegment = HRESULT( __cdecl* )( iContext* ctx, uint32_t n_new, void* user_data ) noexcept;*/
type NewSegmentCallback_Type func(context *IContext, n_new uint32, user_data unsafe.Pointer) EWhisperHWND type NewSegmentCallback_Type func(context *IContext, n_new uint32, user_data unsafe.Pointer) EWhisperHWND