{"id":13408486,"url":"https://github.com/tosone/minimp3","last_synced_at":"2025-08-20T18:32:32.441Z","repository":{"id":50582493,"uuid":"119030622","full_name":"tosone/minimp3","owner":"tosone","description":"Decode mp3 base on https://github.com/lieff/minimp3","archived":false,"fork":false,"pushed_at":"2023-08-02T02:34:26.000Z","size":562,"stargazers_count":120,"open_issues_count":0,"forks_count":19,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-07-31T20:30:53.284Z","etag":null,"topics":["decoder","golang","mp3"],"latest_commit_sha":null,"homepage":"","language":"C","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/tosone.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":"2018-01-26T09:10:31.000Z","updated_at":"2024-07-30T16:02:11.000Z","dependencies_parsed_at":"2024-01-08T14:30:41.062Z","dependency_job_id":"1213dd77-6e91-41b6-a0a9-39547865a7e3","html_url":"https://github.com/tosone/minimp3","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tosone%2Fminimp3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tosone%2Fminimp3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tosone%2Fminimp3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tosone%2Fminimp3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tosone","download_url":"https://codeload.github.com/tosone/minimp3/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230445926,"owners_count":18227060,"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":["decoder","golang","mp3"],"created_at":"2024-07-30T20:00:53.167Z","updated_at":"2024-12-19T14:06:56.652Z","avatar_url":"https://github.com/tosone.png","language":"C","funding_links":[],"categories":["Audio and Music","音频和音乐","Uncategorized","音频和音乐库","音频和视频"],"sub_categories":["Contents"],"readme":"# minimp3\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/tosone/minimp3.svg)](https://pkg.go.dev/github.com/tosone/minimp3) [![Builder](https://github.com/tosone/minimp3/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/tosone/minimp3/actions/workflows/ci.yaml) [![codecov](https://codecov.io/gh/tosone/minimp3/branch/main/graph/badge.svg?token=LUIF0jZw6E)](https://codecov.io/gh/tosone/minimp3)\n\nDecode mp3 base on \u003chttps://github.com/lieff/minimp3\u003e\n\n## Installation\n\n1. The first need Go installed (version 1.15+ is required), then you can use the below Go command to install minimp3.\n\n``` bash\n$ go get -u github.com/tosone/minimp3\n```\n\n2. Import it in your code:\n\n``` bash\nimport \"github.com/tosone/minimp3\"\n```\n\n## Examples are here\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample1: Decode the whole mp3 and play.\u003c/summary\u003e\n\n``` golang\npackage main\n\nimport (\n\t\"io/ioutil\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/hajimehoshi/oto\"\n\t\"github.com/tosone/minimp3\"\n)\n\nfunc main() {\n\tvar err error\n\n\tvar file []byte\n\tif file, err = ioutil.ReadFile(\"test.mp3\"); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar dec *minimp3.Decoder\n\tvar data []byte\n\tif dec, data, err = minimp3.DecodeFull(file); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar context *oto.Context\n\tif context, err = oto.NewContext(dec.SampleRate, dec.Channels, 2, 1024); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar player = context.NewPlayer()\n\tplayer.Write(data)\n\n\t\u003c-time.After(time.Second)\n\n\tdec.Close()\n\tif err = player.Close(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample2: Decode and play.\u003c/summary\u003e\n\n``` go\npackage main\n\nimport (\n\t\"io\"\n\t\"log\"\n\t\"os\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/hajimehoshi/oto\"\n\t\"github.com/tosone/minimp3\"\n)\n\nfunc main() {\n\tvar err error\n\n\tvar file *os.File\n\tif file, err = os.Open(\"../test.mp3\"); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar dec *minimp3.Decoder\n\tif dec, err = minimp3.NewDecoder(file); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tstarted := dec.Started()\n\t\u003c-started\n\n\tlog.Printf(\"Convert audio sample rate: %d, channels: %d\\n\", dec.SampleRate, dec.Channels)\n\n\tvar context *oto.Context\n\tif context, err = oto.NewContext(dec.SampleRate, dec.Channels, 2, 1024); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar waitForPlayOver = new(sync.WaitGroup)\n\twaitForPlayOver.Add(1)\n\n\tvar player = context.NewPlayer()\n\n\tgo func() {\n\t\tfor {\n\t\t\tvar data = make([]byte, 1024)\n\t\t\t_, err := dec.Read(data)\n\t\t\tif err == io.EOF {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tplayer.Write(data)\n\t\t}\n\t\tlog.Println(\"over play.\")\n\t\twaitForPlayOver.Done()\n\t}()\n\twaitForPlayOver.Wait()\n\n\t\u003c-time.After(time.Second)\n\tdec.Close()\n\tif err = player.Close(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample3: Play the network audio.\u003c/summary\u003e\n\n``` go\npackage main\n\nimport (\n\t\"io\"\n\t\"log\"\n\t\"net/http\"\n\t\"os\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/hajimehoshi/oto\"\n\t\"github.com/tosone/minimp3\"\n)\n\nfunc main() {\n\tvar err error\n\n\tvar args = os.Args\n\tif len(args) != 2 {\n\t\tlog.Fatal(\"Run test like this:\\n\\n\\t./networkAudio.test [mp3url]\\n\\n\")\n\t}\n\n\tvar response *http.Response\n\tif response, err = http.Get(args[1]); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar dec *minimp3.Decoder\n\tif dec, err = minimp3.NewDecoder(response.Body); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t\u003c-dec.Started()\n\n\tlog.Printf(\"Convert audio sample rate: %d, channels: %d\\n\", dec.SampleRate, dec.Channels)\n\n\tvar context *oto.Context\n\tif context, err = oto.NewContext(dec.SampleRate, dec.Channels, 2, 4096); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tvar waitForPlayOver = new(sync.WaitGroup)\n\twaitForPlayOver.Add(1)\n\n\tvar player = context.NewPlayer()\n\n\tgo func() {\n\t\tdefer response.Body.Close()\n\t\tfor {\n\t\t\tvar data = make([]byte, 512)\n\t\t\t_, err = dec.Read(data)\n\t\t\tif err == io.EOF {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tlog.Fatal(err)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tplayer.Write(data)\n\t\t}\n\t\tlog.Println(\"over play.\")\n\t\twaitForPlayOver.Done()\n\t}()\n\n\twaitForPlayOver.Wait()\n\n\t\u003c-time.After(time.Second)\n\tdec.Close()\n\tplayer.Close()\n}\n```\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftosone%2Fminimp3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftosone%2Fminimp3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftosone%2Fminimp3/lists"}