'commit'
This commit is contained in:
119
dsLightRag/TongYiTingWu/T1.py
Normal file
119
dsLightRag/TongYiTingWu/T1.py
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
from aliyunsdkcore.client import AcsClient
|
||||||
|
from aliyunsdkcore.request import CommonRequest
|
||||||
|
from aliyunsdkcore.auth.credentials import AccessKeyCredential
|
||||||
|
|
||||||
|
from Config.Config import ALY_AK, ALY_SK
|
||||||
|
|
||||||
|
|
||||||
|
def create_common_request(domain, version, protocolType, method, uri):
|
||||||
|
request = CommonRequest()
|
||||||
|
request.set_accept_format('json')
|
||||||
|
request.set_domain(domain)
|
||||||
|
request.set_version(version)
|
||||||
|
request.set_protocol_type(protocolType)
|
||||||
|
request.set_method(method)
|
||||||
|
request.set_uri_pattern(uri)
|
||||||
|
request.add_header('Content-Type', 'application/json')
|
||||||
|
return request
|
||||||
|
|
||||||
|
|
||||||
|
def init_parameters():
|
||||||
|
body = dict()
|
||||||
|
body['AppKey'] = 'VQRY3Ij1D9MZvym6'
|
||||||
|
|
||||||
|
# 基本请求参数
|
||||||
|
input = dict()
|
||||||
|
input['SourceLanguage'] = 'cn'
|
||||||
|
input['TaskKey'] = 'task' + datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
|
# https://yx.ccsjy.cn/ChangChunCloudSchool/index.html#/course-detail/831993494a63a7087ac1c752dcd25d19
|
||||||
|
# 《数轴的复习》
|
||||||
|
input['FileUrl'] = 'https://ccschool.edusoa.com/cloud_file/project/ccyx-0012/material/26/7c/267c936afcf3e965d463f65c7275d60b.mp4'
|
||||||
|
body['Input'] = input
|
||||||
|
|
||||||
|
# AI相关参数,按需设置即可
|
||||||
|
parameters = dict()
|
||||||
|
|
||||||
|
# 音视频转换相关
|
||||||
|
transcoding = dict()
|
||||||
|
# 将原音视频文件转成mp3文件,用以后续浏览器播放
|
||||||
|
# transcoding['TargetAudioFormat'] = 'mp3'
|
||||||
|
# transcoding['SpectrumEnabled'] = False
|
||||||
|
# parameters['Transcoding'] = transcoding
|
||||||
|
|
||||||
|
# 语音识别控制相关
|
||||||
|
transcription = dict()
|
||||||
|
# 角色分离 : 可选
|
||||||
|
transcription['DiarizationEnabled'] = True
|
||||||
|
diarization = dict()
|
||||||
|
diarization['SpeakerCount'] = 2
|
||||||
|
transcription['Diarization'] = diarization
|
||||||
|
parameters['Transcription'] = transcription
|
||||||
|
|
||||||
|
# 文本翻译控制相关 : 可选
|
||||||
|
parameters['TranslationEnabled'] = True
|
||||||
|
translation = dict()
|
||||||
|
translation['TargetLanguages'] = ['en'] # 假设翻译成英文
|
||||||
|
parameters['Translation'] = translation
|
||||||
|
|
||||||
|
# 章节速览相关 : 可选,包括: 标题、议程摘要
|
||||||
|
parameters['AutoChaptersEnabled'] = True
|
||||||
|
|
||||||
|
# 智能纪要相关 : 可选,包括: 待办、关键信息(关键词、重点内容、场景识别)
|
||||||
|
parameters['MeetingAssistanceEnabled'] = True
|
||||||
|
meetingAssistance = dict()
|
||||||
|
meetingAssistance['Types'] = ['Actions', 'KeyInformation']
|
||||||
|
parameters['MeetingAssistance'] = meetingAssistance
|
||||||
|
|
||||||
|
# 摘要控制相关 : 可选,包括: 全文摘要、发言人总结摘要、问答摘要(问答回顾)
|
||||||
|
parameters['SummarizationEnabled'] = True
|
||||||
|
summarization = dict()
|
||||||
|
summarization['Types'] = ['Paragraph', 'Conversational', 'QuestionsAnswering', 'MindMap']
|
||||||
|
parameters['Summarization'] = summarization
|
||||||
|
|
||||||
|
# ppt抽取和ppt总结 : 可选
|
||||||
|
parameters['PptExtractionEnabled'] = True
|
||||||
|
|
||||||
|
# 口语书面化 : 可选
|
||||||
|
parameters['TextPolishEnabled'] = True
|
||||||
|
|
||||||
|
# 大模型后处理任务全局参数 : 可选
|
||||||
|
parameters['Model'] = 'qwq'
|
||||||
|
parameters['LlmOutputLanguage'] = 'en'
|
||||||
|
|
||||||
|
body['Parameters'] = parameters
|
||||||
|
return body
|
||||||
|
|
||||||
|
|
||||||
|
body = init_parameters()
|
||||||
|
print(body)
|
||||||
|
|
||||||
|
# TODO 请通过环境变量设置您的 AccessKeyId 和 AccessKeySecret
|
||||||
|
credentials = AccessKeyCredential(ALY_AK, ALY_SK)
|
||||||
|
client = AcsClient(region_id='cn-beijing', credential=credentials)
|
||||||
|
|
||||||
|
request = create_common_request('tingwu.cn-beijing.aliyuncs.com', '2023-09-30', 'https', 'PUT',
|
||||||
|
'/openapi/tingwu/v2/tasks')
|
||||||
|
request.add_query_param('type', 'offline')
|
||||||
|
|
||||||
|
request.set_content(json.dumps(body).encode('utf-8'))
|
||||||
|
response = client.do_action_with_exception(request)
|
||||||
|
print("response: \n" + json.dumps(json.loads(response), indent=4, ensure_ascii=False))
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
{'AppKey': 'VQRY3Ij1D9MZvym6', 'Input': {'SourceLanguage': 'cn', 'TaskKey': 'task20250820145400', 'FileUrl': 'https://ccschool.edusoa.com/cloud_file/project/ccyx-0012/material/26/7c/267c936afcf3e965d463f65c7275d60b.mp4'}, 'Parameters': {'Transcription': {'DiarizationEnabled': True, 'Diarization': {'SpeakerCount': 2}}, 'TranslationEnabled': True, 'Translation': {'TargetLanguages': ['en']}, 'AutoChaptersEnabled': True, 'MeetingAssistanceEnabled': True, 'MeetingAssistance': {'Types': ['Actions', 'KeyInformation']}, 'SummarizationEnabled': True, 'Summarization': {'Types': ['Paragraph', 'Conversational', 'QuestionsAnswering', 'MindMap']}, 'PptExtractionEnabled': True, 'TextPolishEnabled': True, 'Model': 'qwq', 'LlmOutputLanguage': 'en'}}
|
||||||
|
response:
|
||||||
|
{
|
||||||
|
"Code": "0",
|
||||||
|
"Data": {
|
||||||
|
"TaskId": "93d5f86d16b74a63aa0f2ecb80297819",
|
||||||
|
"TaskKey": "task20250820145400",
|
||||||
|
"TaskStatus": "ONGOING"
|
||||||
|
},
|
||||||
|
"Message": "success",
|
||||||
|
"RequestId": "27485F01-F17F-53AC-9530-BC1B886362EE"
|
||||||
|
}
|
||||||
|
"""
|
52
dsLightRag/TongYiTingWu/T2.py
Normal file
52
dsLightRag/TongYiTingWu/T2.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import json
|
||||||
|
from aliyunsdkcore.client import AcsClient
|
||||||
|
from aliyunsdkcore.request import CommonRequest
|
||||||
|
from aliyunsdkcore.auth.credentials import AccessKeyCredential
|
||||||
|
|
||||||
|
from Config.Config import ALY_SK, ALY_AK
|
||||||
|
|
||||||
|
|
||||||
|
def create_common_request(domain, version, protocolType, method, uri):
|
||||||
|
request = CommonRequest()
|
||||||
|
request.set_accept_format('json')
|
||||||
|
request.set_domain(domain)
|
||||||
|
request.set_version(version)
|
||||||
|
request.set_protocol_type(protocolType)
|
||||||
|
request.set_method(method)
|
||||||
|
request.set_uri_pattern(uri)
|
||||||
|
request.add_header('Content-Type', 'application/json')
|
||||||
|
return request
|
||||||
|
|
||||||
|
credentials = AccessKeyCredential(ALY_AK, ALY_SK)
|
||||||
|
client = AcsClient(region_id='cn-beijing', credential=credentials)
|
||||||
|
|
||||||
|
uri = '/openapi/tingwu/v2/tasks' + '/' + '93d5f86d16b74a63aa0f2ecb80297819'
|
||||||
|
request = create_common_request('tingwu.cn-beijing.aliyuncs.com', '2023-09-30', 'https', 'GET', uri)
|
||||||
|
|
||||||
|
response = client.do_action_with_exception(request)
|
||||||
|
print("response: \n" + json.dumps(json.loads(response), indent=4, ensure_ascii=False))
|
||||||
|
|
||||||
|
"""
|
||||||
|
# 返回数据的解释【TaskStatus】
|
||||||
|
ONGOING: 当任务仍在运行中时
|
||||||
|
COMPLETED: 当任务已完成时
|
||||||
|
|
||||||
|
https://help.aliyun.com/zh/tingwu/offline-transcribe-of-audio-and-video-files?spm=a2c4g.11186623.0.i2#7e2f92c07989a
|
||||||
|
response:
|
||||||
|
{
|
||||||
|
"Code": "0",
|
||||||
|
"Data": {
|
||||||
|
"TaskId": "93d5f86d16b74a63aa0f2ecb80297819",
|
||||||
|
"TaskKey": "task20250820145400",
|
||||||
|
"TaskStatus": "ONGOING",
|
||||||
|
"Result": {
|
||||||
|
"Translation": "https://prod-tingwu-paas-common-beijing.oss-cn-beijing.aliyuncs.com/tingwu/output/1546399445482588/93d5f86d16b74a63aa0f2ecb80297819/93d5f86d16b74a63aa0f2ecb80297819_Translation_20250820145532.json?Expires=1758264972&OSSAccessKeyId=LTAI5tMzZ1D4o1drkJN1TfCr&Signature=FWHKqwKyekM4ZrK%2FHaJ5oJdwBGc%3D",
|
||||||
|
"MeetingAssistance": "https://prod-tingwu-paas-common-beijing.oss-cn-beijing.aliyuncs.com/tingwu/output/1546399445482588/93d5f86d16b74a63aa0f2ecb80297819/93d5f86d16b74a63aa0f2ecb80297819_MeetingAssistance_20250820145556.json?Expires=1758264972&OSSAccessKeyId=LTAI5tMzZ1D4o1drkJN1TfCr&Signature=cPiV2BbMtykEGVB0C4kGq1kLvGI%3D",
|
||||||
|
"AutoChapters": "https://prod-tingwu-paas-common-beijing.oss-cn-beijing.aliyuncs.com/tingwu/output/1546399445482588/93d5f86d16b74a63aa0f2ecb80297819/93d5f86d16b74a63aa0f2ecb80297819_AutoChapters_20250820145610.json?Expires=1758264972&OSSAccessKeyId=LTAI5tMzZ1D4o1drkJN1TfCr&Signature=7AYDs2xx8jGL7PsiNeDsO6eYbZA%3D",
|
||||||
|
"Transcription": "https://prod-tingwu-paas-common-beijing.oss-cn-beijing.aliyuncs.com/tingwu/output/1546399445482588/93d5f86d16b74a63aa0f2ecb80297819/93d5f86d16b74a63aa0f2ecb80297819_Transcription_20250820145530.json?Expires=1758264972&OSSAccessKeyId=LTAI5tMzZ1D4o1drkJN1TfCr&Signature=hgj4bYngYcur193eVh6unKdIG14%3D"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Message": "success",
|
||||||
|
"RequestId": "EE99A56F-4916-5EA1-8451-C1857CAFD2EA"
|
||||||
|
}
|
||||||
|
"""
|
0
dsLightRag/TongYiTingWu/__init__.py
Normal file
0
dsLightRag/TongYiTingWu/__init__.py
Normal file
8
dsLightRag/TongYiTingWu/通义听悟.txt
Normal file
8
dsLightRag/TongYiTingWu/通义听悟.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
通义听悟AppKey
|
||||||
|
VQRY3Ij1D9MZvym6
|
||||||
|
|
||||||
|
音视频文件离线转写
|
||||||
|
https://help.aliyun.com/zh/tingwu/offline-transcribe-of-audio-and-video-files
|
||||||
|
|
||||||
|
|
||||||
|
pip install aliyun-python-sdk-core
|
Reference in New Issue
Block a user