npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cloudtea/ct-asr

v1.0.2

Published

微信小程序语音识别

Downloads

8

Readme

asr

微信小程序语音识别(ffmpeg + 百度语音识别)

为什么?

微信小程序目前支持录音和回放,但是不支持语音识别和理解, 所以诞生了这个项目. 项目目标: 简洁,高效。

前提条件

  1. 系统需要安装ffmpeg
  2. 服务端需自行实现文件上传, 可参考:https://github.com/expressjs/multer

使用方法

  1. npm install
  2. 小程序中使用recorderManager实现录音,示例代码:
	import wepy from 'wepy';
    import { API } from '../utils/const';
    let recorderManager = wx.getRecorderManager();

    export default class Record extends wepy.page {
        constructor() {
            super();
            let me = this;

            recorderManager.onStart(this.methods.onStart.bind(this));
            recorderManager.onResume(() => {
                console.log('recorder resume')
            });
            recorderManager.onPause(() => {
                console.log('recorder pause')
            });
            recorderManager.onStop(this.methods.onStop.bind(this));
            recorderManager.onFrameRecorded((res) => {
                const { frameBuffer } = res
                console.log('frameBuffer.byteLength', frameBuffer.byteLength)
            });
        }

        methods = {
            onStart() {
                let me = this;
                me.isRecording = true;
                this.$apply();
                console.log('recorder start', me.isRecording)
            },
            onStop(res) {
                let me = this;

                me.isRecording = false;
                me.tempFilePath = res.tempFilePath;
                me.$apply();

                wx.showLoading({
                    title: '识别中...'
                });

                wx.uploadFile({
                    url: API.RECGONIZE, //仅为示例,非真实的接口地址
                    filePath: res.tempFilePath,
                    name: 'myfile',
                    formData:{
                        // 'user': 'test'
                    },
                    success: function(res){
                        wx.hideLoading();

                        var data = JSON.parse(res.data || '{}')
                        
                        console.log(data, data.result);

                        wepy.showModal({
                            content: data.result.toString(),
                            showCancel: false
                        });
                    },
                    fail: error => {
                        wx.hideLoading();
                        console.log(error);
                    }
                });

                console.log('recorder stop', res, me.isRecording)
            },

            recordByManager() {
                const options = {
                    duration: 10000,
                    sampleRate: 16000,
                    numberOfChannels: 1,
                    encodeBitRate: 96000,
                    format: 'aac',
                    frameSize: 50
                };

               if(this.isRecording) {
                    
                    recorderManager.stop();

               } else {

                    this.methods.onStart.call(this);
                    recorderManager.start(options);
               }

            },

            record() {

               if(this.isRecording) {
                    
                    wx.stopRecord();

               } else {

                   this.methods.onStart.call(this);
                   wx.startRecord({
                        success: res => {
                            setTimeout(() => {
                                this.methods.onStop.call(this, res); 
                            }, 50);
                        },
                        fail: res => {
                            //录音失败
                            this.isRecording = false;
                        }
                    });

               }

            }
        }

        data = {
            isRecording: false, 
            tempFilePath: ''
        }
    }
  1. 服务端调用示例:
 	let asr = require('@cloudtea/ct-asr');
	let APP_ID = 'xxx'; // 百度语音识别 APP ID
	let API_KEY = "xxx"; // 百度语音识别 APP KEY
	let SECRET_KEY = "xxx"; // 百度语音识别 SECRET
	asr.init({
		APP_ID: APP_ID,
		API_KEY: API_KEY,
		SECRET_KEY: SECRET_KEY
	}).start('小程序录音上传到服务器的音频路径').then(res => {
		console.log('Result is: ', res);
	});