{"id":18821638,"url":"https://github.com/octu0/go-encodec-cpp","last_synced_at":"2026-01-18T09:30:18.120Z","repository":{"id":204130522,"uuid":"711179967","full_name":"octu0/go-encodec-cpp","owner":"octu0","description":"Go binding for encodec.cpp","archived":false,"fork":false,"pushed_at":"2024-01-10T09:48:30.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-30T03:43:23.318Z","etag":null,"topics":["audio-codec","bindings","encodec"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/octu0/go-encodec-cpp","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/octu0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-10-28T13:01:46.000Z","updated_at":"2023-10-28T14:44:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"70dc6c79-b1c4-4d1a-b3f3-dc181875b2b4","html_url":"https://github.com/octu0/go-encodec-cpp","commit_stats":null,"previous_names":["octu0/go-encodec-cpp"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fgo-encodec-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fgo-encodec-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fgo-encodec-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fgo-encodec-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/octu0","download_url":"https://codeload.github.com/octu0/go-encodec-cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239758900,"owners_count":19692041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio-codec","bindings","encodec"],"created_at":"2024-11-08T00:44:59.197Z","updated_at":"2026-01-18T09:30:18.054Z","avatar_url":"https://github.com/octu0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `go-encodec-cpp`\n\n[![MIT License](https://img.shields.io/github/license/octu0/go-encodec-cpp)](https://github.com/octu0/go-encodec-cpp/blob/master/LICENSE)\n[![GoDoc](https://godoc.org/github.com/octu0/go-encodec-cpp?status.svg)](https://godoc.org/github.com/octu0/go-encodec-cpp)\n[![Go Report Card](https://goreportcard.com/badge/github.com/octu0/go-encodec-cpp)](https://goreportcard.com/report/github.com/octu0/go-encodec-cpp)\n[![Releases](https://img.shields.io/github/v/release/octu0/go-encodec-cpp)](https://github.com/octu0/go-encodec-cpp/releases)\n\nGo binding for [encodec.cpp](https://github.com/PABannier/encodec.cpp)  \n\nencodec.cpp provides a C++ interface, so I create a bridge called `cencodec` (c-encodec-cpp) that can be handled by cgo to call encodec.cpp from Go.\n\n## Installation\n\ninstall `libcencodec.(so|dylib)`\n\n```\n$ git clone https://github.com/octu0/go-encodec-cpp.git\n$ cd go-encodec-cpp/c-encodec-cpp\n$ make install\n```\n\n## Example\n\nCompress\n\n```go\npackage main\n\nimort (\n\t\"os\"\n\t\"runtime\"\n\n\t\"github.com/go-audio/wav\"\n\t\"github.com/octu0/go-encodec-cpp\"\n)\n\nfunc main() {\n\tgpuLayers := 0\n\ttargetBandwidth := 6\n\n\tin, _ := os.Open(\"/path/to/input.wav\")\n\tout, _ := os.Create(\"/path/to/output.compress\")\n\n\twd := wav.NewDecoder(in)\n\tbuf, _ := wd.FullPCMBuffer()\n\n\tectx, _ := encodec.LoadModel(\"/path/to/ggml-model.bin\", gpuLayers)\n\tdefer ectx.Release()\n\n\tectx.SetTargetBandwidth(targetBandwidth)\n\n\tcompressedData, free, _ := ectx.CompressAudio(buf.AsFloat32Buffer().Data, runtime.NumCPU())\n\tdefer free()\n\n\tgob.NewEncoder(out).Encode(ECDC{\n\t\tBitDepth:    32,\n\t\tNumChannels: 1,\n\t\tSampleRate:  24000,\n\t\tAudioFormat: 1,\n\t\tBandwidth:   targetBandwidth,\n\t\tData:        compressedData,\n\t})\n}\n```\n\nDecompress\n\n```go\npackage main\n\nimort (\n\t\"os\"\n\t\"runtime\"\n\n\t\"github.com/go-audio/wav\"\n\t\"github.com/octu0/go-encodec-cpp\"\n)\n\nfunc main() {\n\tgpuLayers := 0\n\n\tin, _ := os.Open(\"/path/to/input.compress\")\n\tout, _ := os.Create(\"/path/to/output.wav\")\n\n\tecdc := ECDC{}\n\tgob.NewDecoder(in).Decode(\u0026ecdc)\n\n\tectx, _ := encodec.LoadModel(\"/path/to/ggml-model.bin\", gpuLayers)\n\tdefer ectx.Release()\n\n\tectx.SetTargetBandwidth(ecdc.Bandwidth)\n\n\tdecompressData, free, _ := ectx.DecompressAudio(ecdc.Data, runtime.NumCPU())\n\tdefer free()\n\n\twe := wav.NewEncoder(out, ecdc.SampleRate, 16, ecdc.NumChannels, ecdc.AudioFormat)\n\tfor _, d := range decompressData {\n\t\td *= 0x7fff\n\t\tswitch {\n\t\tcase 0x7fff \u003c d:\n\t\t\td = 0x7fff\n\t\tcase d \u003c -0x8000:\n\t\t\td = -0x8000\n\t\tcase 0 \u003c d:\n\t\t\td += 0.5\n\t\tcase d \u003c 0:\n\t\t\td -= -0.5\n\t\t}\n\t\twe.WriteFrame(int16(d))\n\t}\n}\n```\n\nSee [_example](https://github.com/octu0/go-encodec-cpp/tree/master/_example) for more details\n\n## License\n\nMIT, see LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fgo-encodec-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctu0%2Fgo-encodec-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fgo-encodec-cpp/lists"}