• 腾讯云字幕接口api整理笔记


    **

    腾讯云字幕接口API接口整理的在这里做个笔记分享

    **

    这个是腾讯云字幕接口官方地址
    字幕平台接口文档地址:https://transfy.cloud.tencent.com/#/api/commonParams

    以下代码需要注意的地方是时间一定要传10位的时间戳不然就会报错

    package com.example.demo.demo1;
    
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.math.BigInteger;
    import java.net.URL;
    import java.net.URLConnection;
    import java.security.MessageDigest;
    import java.util.List;
    import java.util.Map;
    
    public class demo01 {
    
    	
    	
    	public static void main(String[] args) throws Exception {
    		
    		
    //		creatRoom();
    		
    		new demo01().stopTask("2");
    		
    		
    		
    		
    		
    	}
    	
    	
    
    	public final static String appid = "你申请的appid";
    	
    	public final static String SecretKey = "你的秘钥"; 
    	
    	
    	
    	//--------------------------下面的这几个接口可以放到你的server或者工具类里都可以-------------------------------
    	
    	
    	
    	
    	
    	/**
    	 * 创建字幕任务
    	 * @param roomId 唯一的房间号
    	 * @param title  房间名称
    	 * @param liveStreamURL 直播流地址
    	 * @param srcLang  直播流的语言类型
    	 * @param startTime  开始时间 10位的时间戳
    	 * @param endTime    结束时间 10位的时间戳
    	 * @throws Exception
    	 */
    	public  void creatRoom(String roomId,String title,String liveStreamURL,String srcLang,String startTime,String endTime) throws Exception {
    		 String ts =  System.currentTimeMillis()/1000+"";
    		 Integer code = (int)(Math.random()*10000);
    		 commonGetUrl("https://api.aitransfy.com/api/online/createTask?"+commonParam(ts,code)+"&roomId="+roomId+"&title="+title+"&liveStreamURL="+liveStreamURL+"&srcLang="+srcLang+"&startTime="+startTime+"&endTime="+endTime);
    	}
    	
    	
    	
    	
    	/**
    	 * 停止字幕任务-根据房间号
    	 * @param roomId
    	 * @throws Exception
    	 */
    	public  void  stopTask(String roomId) throws Exception {
    		 String ts =  System.currentTimeMillis()/1000+"";
    		 Integer code = (int)(Math.random()*10000);
    		 commonGetUrl("https://api.aitransfy.com/api/online/stopTask?"+commonParam(ts,code)+"&roomId="+roomId);
    	}
    	
    	
    	
    	/**
    	 * 重新开启字幕任务
    	 * @param roomId 唯一的房间号
    	 * @param startTime  开始时间   10位的时间戳
    	 * @param endTime    结束时间   10位的时间戳
    	 * @throws Exception
    	 */
    	public  void  stopTask(String roomId,String startTime,String endTime) throws Exception {
    		 String ts =  System.currentTimeMillis()/1000+"";
    		 Integer code = (int)(Math.random()*10000);
    		 commonGetUrl("https://api.aitransfy.com/api/online/restartTask?"+commonParam(ts,code)+"&roomId="+roomId);
    	}
    	
    	/**
    	 * 查询字幕任务
    	 * @param roomId  唯一房间号
    	 * @throws Exception
    	 */
    	public  void qureyTask(String roomId)throws Exception {
    		String ts =  System.currentTimeMillis()/1000+"";
    		 Integer code = (int)(Math.random()*10000);
    		 commonGetUrl("https:/api.aitransfy.com/api/online/queryTask?"+commonParam(ts,code)+"&roomId="+roomId);
    	}
    	
    	
    	/**
    	 * 获取字幕消息
    	 * @param roomId  唯一的房间号
    	 * @param lang	  选择用户需要观看的语种。
    	 */
    	public  void export(String roomId,String lang)throws Exception {
    		String ts =  System.currentTimeMillis()/1000+"";
    		 Integer code = (int)(Math.random()*10000);
    		 commonGetUrl("https:/api.aitransfy.com/api/online/export?"+commonParam(ts,code)+"&roomId="+roomId+"&lang="+lang);
    		
    	}
    	
    	
    	
    	
    	
    	
    	//---------------------以下方法可以方法一个工具类里--------------------------------
    	
    	
    	/**
    	 * 签名生成
    	 * @param ts
    	 * @param code
    	 * @return
    	 * @throws Exception
    	 */
    	public  String sign(String ts,int code) throws Exception {
    		return getMD5String(appid+ts+SecretKey+code);
    		
    	}
    	/**
    	 * 通用的请求参数
    	 * @param ts
    	 * @param code
    	 * @return
    	 */
    	public  String commonParam(String ts,Integer code)throws Exception {
    		return "appId="+appid+"&nOnce="+code+"&ts="+ts+"&sign="+sign(ts,code);
    	}
    	/**
    	 * md5加密
    	 * @param str
    	 * @return
    	 */
    	public static String getMD5String(String str) {
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(str.getBytes());
                return new BigInteger(1, md.digest()).toString(16);
            } catch (Exception e) {
               e.printStackTrace();
               return null;
            }
        }
    	
    	/**
    	 * 通用的get的url方法
    	 * @param url
    	 */
    	public static void commonGetUrl(String url)  throws Exception {
    		String result = "";
    		 BufferedReader in = null;
    		URL ss = new URL(url);
    		URLConnection connection = ss.openConnection();
    
    		   connection.setRequestProperty("Accept-Charset","UTF-8");
    
    		   connection.setRequestProperty("Content-Type","text/plain; charset=utf-8");
    		   // 建立实际的连接
    		   connection.connect();
    		   // 获取所有响应头字段
    		   Map<String, List<String>> map = connection.getHeaderFields();
    		   // 遍历所有的响应头字段
    		   for (String key : map.keySet()) {
    		    System.out.println(key + "--->" + map.get(key));
    		   }
    		 
    		   // 定义 BufferedReader输入流来读取URL的响应
    		   in = new BufferedReader(new InputStreamReader(
    		     connection.getInputStream(),"UTF-8"));
    		   String line;
    		   while ((line = in.readLine()) != null) {
    		    result += line;
    		   }
    		System.out.println(result);
    	}
    
    	
    	
    	
    	
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193

    在测试的时候,直接把官方给的网页接口在浏览器访问等待几秒钟就会出现你们的测试记录,这个相应速度是比较快的,当然价格也比较贵
    在这里插入图片描述

  • 相关阅读:
    数组内容整体左移一次
    美颜SDK怎么用?美颜SDK可以应用到哪些场景?
    springboot+vue+elementui外卖点餐系统骑手,商家
    ubuntu 23.04安装中文输入法
    【codeforces】1673C. Palindrome Basis(DP划分,回文数判定)
    GD32F303固件库开发(8)----USART收发配置
    SQL 注入绕过(四)
    微信小程序
    GO微服务实战第六节 Go 语言开发快速回顾:语法、数据结构和流程控制
    【WinForm详细教程八】WinForm中的TreeView控件
  • 原文地址:https://blog.csdn.net/weixin_43852094/article/details/125615328