Skip to content

Commit

Permalink
add tongyi speech to text
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Jul 4, 2024
1 parent f60143f commit 588adde
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions scripts/speech_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,52 +83,52 @@ def get_note(transId):
response = requests.post(url, headers=headers, json=payload)
if response.ok:
note = response.json().get("data").get("content")
if note is None:
return None
data = json.loads(response.json().get("data").get("content"))
children = []
for paragraph in data:
type = "paragraph"
skip_outer = False
is_checked = False
rich_text = []
if isinstance(paragraph, list):
for span in paragraph:
if isinstance(span,dict):
if "list" in span:
type="bulleted_list_item"
isOrdered = span.get("list").get("isOrdered")
isTaskList = span.get("list").get("isTaskList")
if isOrdered:
type="numbered_list_item"
if isTaskList:
type = "to_do"
is_checked = span.get("list").get("isChecked")
if isinstance(span, list):
if(span[0]=='span'):
for i in range(2, len(span)):
bold = False
highlight = False
content = span[i][2]
if "bold" in span[i][1]:
bold = span[i][1].get("bold")
if "highlight" in span[i][1]:
highlight = True
rich_text.append(get_text(content,bold,highlight))
if span[0]=='tag':
time = utils.format_milliseconds(span[1].get("metadata").get("time"))
rich_text.append({"type": "text","text": {"content": time},"annotations": {"underline": True,"color":"blue"}})
if span[0]=='img':
skip_outer = True
url = span[1].get("src")
children.append({"type": "image","image": {"type": "external","external": {"url":url}}})
if skip_outer:
continue
child = {"type": type,type: {"rich_text": rich_text,"color": "default"}}
if type=="to_do":
child[type]["checked"] = is_checked
children.append(child)
return children
print(note)
if note:
data = json.loads(content)
children = []
for paragraph in data:
type = "paragraph"
skip_outer = False
is_checked = False
rich_text = []
if isinstance(paragraph, list):
for span in paragraph:
if isinstance(span,dict):
if "list" in span:
type="bulleted_list_item"
isOrdered = span.get("list").get("isOrdered")
isTaskList = span.get("list").get("isTaskList")
if isOrdered:
type="numbered_list_item"
if isTaskList:
type = "to_do"
is_checked = span.get("list").get("isChecked")
if isinstance(span, list):
if(span[0]=='span'):
for i in range(2, len(span)):
bold = False
highlight = False
content = span[i][2]
if "bold" in span[i][1]:
bold = span[i][1].get("bold")
if "highlight" in span[i][1]:
highlight = True
rich_text.append(get_text(content,bold,highlight))
if span[0]=='tag':
time = utils.format_milliseconds(span[1].get("metadata").get("time"))
rich_text.append({"type": "text","text": {"content": time},"annotations": {"underline": True,"color":"blue"}})
if span[0]=='img':
skip_outer = True
url = span[1].get("src")
children.append({"type": "image","image": {"type": "external","external": {"url":url}}})
if skip_outer:
continue
child = {"type": type,type: {"rich_text": rich_text,"color": "default"}}
if type=="to_do":
child[type]["checked"] = is_checked
children.append(child)
return children
else:
print("请求失败")

Expand Down

0 comments on commit 588adde

Please sign in to comment.