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

@muguilin/xf-voice-dictation

v1.0.1

Published

讯飞语音听写 WebAPI

Downloads

60

Readme

@muguilin/xf-voice-dictation

MIT License

基于 讯飞语音听写流式接口 进行二次封装,用于在 1 分钟内的即时语音转文字技术,支持实时返回识别结果,达到一边上传音频一边获得识别文本的效果。

该语音能力是通过 Websocket API 的方式给开发者提供一个通用的接口。Websocket API 具备流式传输能力,适用于需要流式数据传输的 AI 服务场景,比如边说话边识别。相较于 SDK,API 具有轻量、跨语言的特点;相较于 HTTP API,Websocket API 协议有原生支持跨域的优势。

🏡 下载安装:

# 使用npm命令下载安装
$ npm i @muguilin/xf-voice-dictation

# 使用yarn命令下载安装
$ yarn add @muguilin/xf-voice-dictation

🔍 实例效果:

语音听写 DEMO(流式版)WebAPI (muguilin.github.io)

讯飞语音听写(流式版)WebAPI 文档 | (xfyun.cn)

🚀 使用方法:

【关于:】服务接口认证信息这 3 个参数据:APPID、APISecret、APIKey,请到官网申请(https://www.xfyun.cn/services/voicedictation)

【注意:】APISecret 和 APIKey 的长度都差不多很相似,所以要填错哦!

import { XfVoiceDictation } from '@muguilin/xf-voice-dictation';

let times = null;
const xfVoice = new XfVoiceDictation({
    APPID: 'xxx',
    APISecret: 'xxx',
    APIKey: 'xxx',

    // webSocket请求地址 非必传参数,默认为:wss://iat-api.xfyun.cn/v2/iat
    // url: '',

    // 监听录音状态变化回调
    onWillStatusChange: function (oldStatus, newStatus) {
        // 可以在这里进行页面中一些交互逻辑处理:注:倒计时(语音听写只有60s),录音的动画,按钮交互等!
        console.log('识别状态:', oldStatus, newStatus);
    },

    // 监听识别结果的变化回调
    onTextChange: function (text) {
        // 可以在这里进行页面中一些交互逻辑处理:如将文本显示在页面中
        console.log('识别内容:',text)

        // 如果3秒钟内没有说话,就自动关闭(60s后也会自动关闭)
        if (text) {
            clearTimeout(times);
            times = setTimeout(() => {
                this.stop();
            }, 3000);
        };
    },

    // 监听识别错误回调
    onError: function(error){
        console.log('错误信息:', error)
    }
});


// 给Dom元素加添事件,来调用开始语音识别!
// xfVoice.start();


// 给Dom元素加添事件,来调用关闭语音识别!
// xfVoice.stop();