使用函数计算来构建小程序

使用函数计算来构建小程序

传统服务器架构 VS Serverless架构

mark

Serverless架构

mark

  • Login & Auth

    微信登录状态维护

    mark

  • 语音识别

    • 音频格式转换

      使用ffpmeg来实现音频转换

      //使用ffmpeg将mp3转化为wav
      String bashCommand = String.format("./ffmpeg -y -i %s %s", mp3Filename, wavFilename);
      String lsCommand = "ls";
      Runtime runtime = Runtime.getRuntime();
      commandExec(lsCommand, runtime);
      commandExec(bashCommand, runtime);
    • 百度语音识别

      文档地址:百度语音识别

      Java实现:

          /**
          * 调用百度语音接口
          *
          * @param path   语音文件路径
          * @param format 文件格式
          * @return 语音识别结果
          */
          private static JSONObject getSpeechResult(String path, String format) {
              // 初始化一个AipSpeech
              AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);
              // 可选:设置网络连接参数
              client.setConnectionTimeoutInMillis(2000);
              client.setSocketTimeoutInMillis(60000);
      
              HashMap<String, Object> options = new HashMap<>(2);
              options.put("lan", "zh");
              // 调用接口
              return JSONObject.parseObject(client.asr(path, format, 16000, options).toString());
          }

函数计算

  • 开通阿里云函数计算服务(当然腾讯云也有一样的功能)

  • 购买域名,备案,申请ssl证书(又拍云免费)

  • 开通 微信小程序 开发认证,以及 百度语音识别

  • 创建服务端

    • 登录状态维护接口

    • 语言文字转换接口

  • 使用 fcli 上传函数

    建议使用 Linux 环境

    • fcli地址

    • fcli 可执行文件所在的文件夹下,./fcli shell 进入交互模式。第一次使用需要输入配置信息。

    • mks myService

      新建一个服务,不带任何高级配置内容

    • cd myService

    • mkf myFunction -h com.xu.t3.HelloFC::handleRequest -d E:\test -t java8

      新建一个函数,-h指定函数入口,-d指定了代码所在目录,-t指定runtime

  • 以函数计算作为 API 网关后端服务

  • 创建微信小程序

猜你喜欢

转载自blog.csdn.net/myherux/article/details/79571385