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

思路

  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);
            }
        }
    }

需要的后台私信我。

相关推荐
Flamingˢ16 小时前
ZYNQ + OV5640 + HDMI 视频系统调试记录:一次 RGB888 与 RGB565 引发的黑屏问题
arm开发·嵌入式硬件·fpga开发·vim·音视频
Flamingˢ18 小时前
YNQ + OV5640 视频系统开发(二):OV5640_Data IP 核源码解析
arm开发·嵌入式硬件·网络协议·tcp/ip·fpga开发·vim·音视频
Flamingˢ18 小时前
ZYNQ + OV5640 视频系统开发(三):AXI VDMA 帧缓存原理
arm开发·嵌入式硬件·fpga开发·vim·音视频
Hello World . .19 小时前
Linux:Linux命令行音视频播放器
linux·音视频
飞翔的SA19 小时前
MLX‑VLM :Mac本地跑通多模态大模型的开源项目!让图片、音频、视频理解一键上手
人工智能·python·macos·音视频
愚公搬代码1 天前
【愚公系列】《剪映+DeepSeek+即梦:短视频制作》046-转场:短视频一气呵成的秘密(什么是转场)
人工智能·音视频
PiaoShiSun2 天前
小米手机浏览器缓存视频如何导出
缓存·智能手机·音视频
艾为电子2 天前
【新品发布】攻克音频切换痛点|艾为 AW35331FDR 高保真音频开关全新登场
音视频
愚公搬代码2 天前
【愚公系列】《剪映+DeepSeek+即梦:短视频制作》047-转场:短视频一气呵成的秘密(转场类型)
人工智能·音视频
开开心心就好2 天前
一键隐藏桌面图标任务栏的实用工具
人工智能·pdf·音视频·语音识别·媒体·测试覆盖率·威胁分析