{"id":29926765,"url":"https://github.com/ecomfe/basr","last_synced_at":"2025-10-11T10:39:23.126Z","repository":{"id":66124792,"uuid":"47023886","full_name":"ecomfe/basr","owner":"ecomfe","description":"Baidu Automatic Speech Recognition for JS","archived":false,"fork":false,"pushed_at":"2015-11-28T13:12:01.000Z","size":11,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-09-03T03:03:53.934Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ecomfe.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}},"created_at":"2015-11-28T13:08:16.000Z","updated_at":"2019-07-14T21:32:02.000Z","dependencies_parsed_at":"2023-02-19T23:00:53.318Z","dependency_job_id":null,"html_url":"https://github.com/ecomfe/basr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ecomfe/basr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fbasr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fbasr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fbasr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fbasr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomfe","download_url":"https://codeload.github.com/ecomfe/basr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fbasr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006855,"owners_count":26084207,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-08-02T12:43:11.105Z","updated_at":"2025-10-11T10:39:23.086Z","avatar_url":"https://github.com/ecomfe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# basr\n\nBaidu Automatic Speech Recognition for JS\n\n百度语音识别 JS SDK\n\n使用 [百度语音](http://yuyin.baidu.com/) 的 [语音识别API](http://yuyin.baidu.com/docs/asr/54)，为页面提供语音识别能力。\n\n## Usage\n\n```js\nimport basr from 'basr';\n\nbasr\n    .authorize({token: 'xxxx'}) // 语音识别 Access Token\n    .then(\n        () =\u003e {\n            // 开始语音采集\n            let voice = basr.start();\n            // 录音 5 秒\n            setTimeout(\n                () =\u003e {\n                    voice\n                        .end() // 结束语音采集\n                        .result() // 进行语音识别\n                        .then(\n                            text =\u003e {\n                                // text 就是识别结果\n                            },\n                            error =\u003e {\n                                // Oops ... 识别出错了...\n                            }\n                        );\n                },\n                5000\n            );\n        },\n        () =\u003e alert('如要使用语音识别，请授权麦克风操作')\n    );\n\n```\n\n完整的演示请参考 [demo/index.html]()。如要在本地运行 demo，请先确保已安装了 [edp](http://ecomfe.github.io/edp/)，并在 `demo/index.html` 的 94 行中填入已申请到的[百度语音 Access Token](http://yuyin.baidu.com/docs/asr/56)，然后在项目根目录下使用 `edp webserver` 命令启动本地调试服务器，访问 `http://127.0.0.1:8848/demo/index.html` 查看最终的效果\n\n## API\n\n### Methods\n\n#### authorize(options)\n\n语音采集授权，提示用户授权麦克风的使用权限，进行语音采集之前必须调用此方法\n\n* **options** `{Object}` 配置参数\n    * **token** `{string}` 语音识别的 token, 具体请参见 [百度语音关于 Access Token 的说明](http://yuyin.baidu.com/docs/asr/56)\n    * **url** `{string=}` 语音识别 API 地址，目前由于线上服务暂时不支持跨域通信，请设置此参数为本地的 API 代理地址\n* _return_ `{Promise}` 授权结果\n\n#### start(options)\n\n语音采集\n\n* **options** `{Object=}` 录音参数\n    * **lang** `{string=}` 语言种类，支持 `zh`(中文)、`ct`(粤语)、`en`(英文)，默认为 `zh`\n    * **sampleRate** `{string=}` 语音识别的采样率，可选 `8000`、`16000`，默认为 `8000`，采样率与数据传输量成正比\n* _return_ `{Object}` [语音对象](#voice)\n\n#### recognize(voice, options)\n\n语音识别\n\n* **voice** `{Float32Array}` 语音数据\n* **options** `{Object}` 配置信息\n    * **token** `{string}` 语音识别 token\n    * **sampleRate** `{number}` 输入语音的采样率\n    * **lang** `{string=}` 语言种类，支持 `zh`(中文)、`ct`(粤语)、`en`(英文)，默认为 `zh`\n    * **outputSampleRate** `{number=}` 语音识别的采样率，可选 `8000`、`16000`，默认为 `8000`\n\n### Voice\n\n语音对象\n\n#### end()\n\n停止语音采集\n\n#### result()\n\n获取语音识别结果\n\n* _return_ `{Promise}`\n\n#### wav(sampleRate)\n\n将语音导出成 wav 格式\n\n* **sampleRate** `{number}` WAV 的采样率，可选 `8000`、`16000`，默认为 `8000`\n* _return_ `{ArrayBuffer}`\n\n```js\n...\nlet wav = voice.wav();\nlet audio = document.createElement('audio');\naudio.setAttribute('autoplay', 'autoplay');\naudio.src = URL.createObjectURL(new Blob(wav, {type: 'audio/wav'}));\ndocument.body.appendChild(audio);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fbasr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomfe%2Fbasr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fbasr/lists"}