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

@neunit/cloud-sdk

v0.0.3

Published

JavaScript SDK for 新联云

Downloads

2

Readme

cloud-sdk-js

一、前期准备

  1. 首先,JS SDK 需要浏览器支持基本的 HTML5 特性,以便计算音频流 base64 值。
  2. 注册登录 新联云管理中心控制台
  3. 前往 云API密钥 的控制台页面,获取或创建您的项目 SecretId 和 SecretKey。

SecretKey 必须严格保管,避免泄露。

二、计算签名

由于签名计算放在前端会暴露 SecretId 和 SecretKey,我们把签名计算过程放在后端实现,前端通过 ajax 向后端获取签名结果,正式部署时请在后端加一层自己网站本身的权限检验。

签名例子:

三、录音识别例子

  1. 创建 test.html,填入下面的代码。
  2. 部署好后端的签名服务,并修改 getAuthorization 里的签名服务地址
  3. 把 test.html 放在 Web 服务器下,然后在浏览器访问页面,测试录音识别
<script src="dist/sc/sc-js-sdk.min.js"></script>
<script>
// 初始化实例
var sc = new SC({
  getAuthorization: function (options, callback) {
    var url = 'http://127.0.0.1:3000/sts'; // 这里替换成您的服务接口地址
    var xhr = new XMLHttpRequest();
    xhr.open('POST', url, true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.onload = function (e) {
      try {
        var data = JSON.parse(e.target.responseText);
        var credentials = data.credentials;
      } catch (e) {}
      if (!data || !credentials) {
        return console.error('credentials invalid:\n' + JSON.stringify(data, null, 2));
      }
      callback({
        Authorization: credentials.Authorization,
        Nonce: credentials.Nonce,
        Timestamp: credentials.Timestamp,
        SecretId: credentials.SecretId,
      });
    };
    xhr.send(options.Body);
  }
});

sc.getScInfo({
  audioChunk: 'pcm 格式的音频二进制流 base64 后的内容' 
}, (err, response) => {
  // 请求异常返回,打印异常信息
  if (err) {
    console.log(err)
    return
  }
  // 请求正常返回,打印response对象
  console.log(response)
});

</script>

webpack 引入方式

支持 webpack 打包的场景,可以用 npm 引入作为模块

npm i @neunit/cloud-sdk-js --save
import XLCLOUD from '@neunit/cloud-sdk-js';

const { SC } = XLCLOUD;
const sc = new SC({
  getAuthorization: (options, callback) => {
    // ...
  },
});

sc.getScInfo({
  audioChunk: 'pcm 格式的音频二进制流 base64 后的内容',
}, (err, response) => {
  // ...
});

Start Demo

1. git clone cloud-sdk-js 至本地
2. cd cloud-sdk-js 进入根目录后执行:npm install
3. 修改 server 文件夹中 sts.js 中的 secretId、secretKey 配置;
4. npm run server # 用 node 启动服务
5. 浏览器输入 http://127.0.0.1:3000/ 即可进行 demo 演示

说明文档

接口文档

公共错误码