41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
|
from http import HTTPStatus
|
||
|
from dashscope.audio.asr import Transcription
|
||
|
import dashscope
|
||
|
import requests
|
||
|
|
||
|
|
||
|
|
||
|
def music_analysis(music_url):
|
||
|
transcribe_response = Transcription.async_call(
|
||
|
model='paraformer-v2',
|
||
|
file_urls=[music_url],
|
||
|
language_hints=['zh', 'en'] # “language_hints”只支持paraformer-v2模型
|
||
|
)
|
||
|
|
||
|
while True:
|
||
|
if transcribe_response.output.task_status == 'SUCCEEDED' or transcribe_response.output.task_status == 'FAILED':
|
||
|
break
|
||
|
transcribe_response = Transcription.fetch(task=transcribe_response.output.task_id)
|
||
|
|
||
|
if transcribe_response.status_code == HTTPStatus.OK:
|
||
|
url=transcribe_response.output['results'][0]['transcription_url']
|
||
|
print(url)
|
||
|
|
||
|
# 发送GET请求
|
||
|
response = requests.get(url)
|
||
|
text = ''
|
||
|
|
||
|
# 验证响应状态
|
||
|
if response.status_code == 200:
|
||
|
# 解析JSON数据
|
||
|
data = response.json()
|
||
|
for transcripts in data['transcripts']:
|
||
|
text += transcripts['text']
|
||
|
|
||
|
else:
|
||
|
print(f"请求失败,状态码:{response.status_code}")
|
||
|
return text
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
music_analysis('https://lf26-music-east.douyinstatic.com/obj/ies-music-hj/7494207652008839996.mp3')
|