下载分享抖音视频并转成文本

思路

  1. 将分享的链接转义成可以正常链接。
  2. 通过链接去找到对应的视频链接。
  3. 在通过返回的html。解析里面视频的资源链接在playAddr字段里面。
  4. 拿到链接后转义urlPath即可获取到资源信息。
  5. 下载视频。
  6. 科大讯飞语音转文本。
  7. 处理json保存到本地。

部分代码

获取抖音链接:

java 复制代码
            String url = "6.43 复制打开抖音,看看【白浪源烟薯种植基地的作品】一旦找对了原产地,就很难在换其他家了,在我们家买过... https://v.douyin.com/ikagBCYn/ [email protected] mqe:/ 05/30  ";
            //过滤链接,获取http连接地址
            url = decodeHttpUrl(url);
            log.info("过滤后的链接地址:{}", url);
            //发起请求
            HttpResponse responseHref = HttpRequest.get(url)
                    .header("User-Agent", USER_AGENT)
                    .execute();
            String strUrlHref = responseHref.body();
            log.info("html地址:{}", strUrlHref);
            // 正则表达式用于匹配"video/"后面跟随的一系列数字
            Pattern pattern = Pattern.compile(regex);
            Matcher matcherUrlHref = pattern.matcher(strUrlHref);
            String videoId = null;

科大讯飞:

java 复制代码
    private static String upload(String filePath) throws SignatureException, FileNotFoundException {
        HashMap<String, Object> map = new HashMap<>(16);
        File audio = new File(filePath);
        String fileName = audio.getName();
        long fileSize = audio.length();
        map.put("appId", appid);
        map.put("fileSize", fileSize);
        map.put("fileName", fileName);
        map.put("duration", "200");
        LfasrSignature lfasrSignature = new LfasrSignature(appid, keySecret);
        map.put("signa", lfasrSignature.getSigna());
        map.put("ts", lfasrSignature.getTs());

        String paramString = HttpUtil.parseMapToPathParam(map);
        log.info("upload paramString:" + paramString);

        String url = HOST + "/v2/api/upload" + "?" + paramString;
        log.info("upload_url:" + url);
        String response = HttpUtil.iflyrecUpload(url, new FileInputStream(audio));

        log.info("upload response:" + response);
        return response;
    }

    private static String getResult(String orderId, String writerFileNameAndPath) throws SignatureException, InterruptedException, IOException {
        HashMap<String, Object> map = new HashMap<>(16);
        map.put("orderId", orderId);
        LfasrSignature lfasrSignature = new LfasrSignature(appid, keySecret);
        map.put("signa", lfasrSignature.getSigna());
        map.put("ts", lfasrSignature.getTs());
        map.put("appId", appid);
        map.put("resultType", "transfer,predict");

        String paramString = HttpUtil.parseMapToPathParam(map);
        String url = HOST + "/v2/api/getResult" + "?" + paramString;
        log.info("\nget_result_url:" + url);
        while (true) {
            String response = HttpUtil.iflyrecGet(url);
            JsonParse jsonParse = gson.fromJson(response, JsonParse.class);
            if (jsonParse.content.orderInfo.status == 4 || jsonParse.content.orderInfo.status == -1) {
                log.info("转换响应完成:" + response);
                write(response, writerFileNameAndPath);
                return response;
            } else {
                log.info("进行中...,状态为:" + jsonParse.content.orderInfo.status);
                //建议使用回调的方式查询结果,查询接口有请求频率限制
                Thread.sleep(7000);
            }
        }
    }

需要的后台私信我。

相关推荐
Hygge-star5 小时前
Flask音频处理:构建高效的Web音频应用指南
前端·flask·音视频·pygame·csdn开发云
hao_wujing13 小时前
使用有限计算实现视频生成模型的高效训练
音视频
追随远方14 小时前
Android音频开发:Speex固定帧与变长帧编解码深度解析
android·音视频
aqi0016 小时前
FFmpeg开发笔记(六十四)使用国产的RedPlayer播放器观看网络视频
android·ffmpeg·音视频·直播·流媒体
英英_1 天前
视频爬虫的Python库
开发语言·python·音视频
weixin_527550401 天前
Linux 环境下高效视频切帧的实用指南
linux·运维·音视频
ai产品老杨1 天前
减少交通拥堵、提高效率、改善交通安全的智慧交通开源了。
前端·vue.js·算法·ecmascript·音视频
红米饭配南瓜汤1 天前
WebRTC中的几个Rtp*Sender
网络·网络协议·音视频·webrtc·媒体
EasyDSS2 天前
EasyRTC嵌入式音视频通信SDK助力物联网/视频物联网音视频打造全场景应用
人工智能·音视频
aqi002 天前
FFmpeg开发笔记(六十三)FFmpeg使用vvenc把视频转为H.266编码
ffmpeg·音视频·直播·流媒体