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

思路

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

部分代码

获取抖音链接:

java 复制代码
            String url = "6.43 复制打开抖音,看看【白浪源烟薯种植基地的作品】一旦找对了原产地,就很难在换其他家了,在我们家买过... https://v.douyin.com/ikagBCYn/ I@V.Lw 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);
            }
        }
    }

需要的后台私信我。

相关推荐
小猴子爱上树15 小时前
跨境图片翻译工具,批量处理商品图视频字幕
python·音视频
2301_8059629315 小时前
在昉星光2(RISC-V)上构建每日短视频自动生成器
音视频·risc-v
xyz_CDragon16 小时前
MiniMax H3 vs Seedance 2.5 vs Kling 3.0:2026 AI视频生成模型横评(排行榜+价格+开源实测)
人工智能·开源·音视频·transformer·minmax h3
程序员老陆16 小时前
FFmpeg libswresample 模块的关键函数swr_convert 到底在干嘛?
ffmpeg·音视频·格式转换·音频重采样
csdnfanguyinheng17 小时前
端到端加密音视频通话系统
音视频
show4331 天前
2026小程序端视频转文字技术对比:识别引擎精度实测
小程序·音视频
南山电子nscn1 天前
国巨RT2512系列薄膜精密电阻在音频放大器中的应用及技术优势解析
音视频·薄膜精密电阻
starzy19901 天前
Soloop 智能视频创作全流程实战指南
数据库·microsoft·音视频
xingyuzhisuan1 天前
星宇智算 AI 视频工作台・图生视频(首尾帧)・Vidu:双模型可控动态过渡生成应用
人工智能·计算机视觉·音视频
zandy10111 天前
全价位数字调音台横向解析:覆盖国产与进口机型,按预算、应用场景对照选型指南
音视频·数字调音台