使用函數計算來構建小程序
傳統服務器架構 VS Serverless架構
Serverless架構
Login & Auth
語音識別
音頻格式轉換
使用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 shell
進入交互模式。第一次使用需要輸入配置信息。mks myService
新建一個服務,不帶任何高級配置內容
cd myService
mkf myFunction -h com.xu.t3.HelloFC::handleRequest -d E:\test -t java8
新建一個函數,-h指定函數入口,-d指定了代碼所在目錄,-t指定runtime
以函數計算作爲 API 網關後端服務
創建微信小程序