Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
funasr_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5f29a5c1
authored
Dec 13, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]听悟脚本
1 parent
5ddd0e26
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
4 deletions
mysql_service/funasr_db.py
mysql_service/mysql_pool.py
utils/ali/test_03_car.py
utils/finetune.py
mysql_service/funasr_db.py
View file @
5f29a5c
...
@@ -157,3 +157,24 @@ def select_reception_material_data(table_name: str, config_id):
...
@@ -157,3 +157,24 @@ def select_reception_material_data(table_name: str, config_id):
t.deleted_flag = 'N' and t.merchant_config_id =
%
s"""
t.deleted_flag = 'N' and t.merchant_config_id =
%
s"""
)
)
return
pool
.
select_all
(
sql
,
(
config_id
))
return
pool
.
select_all
(
sql
,
(
config_id
))
def
select_tingwu_ask_res
():
sql
=
(
f
"""select * from tingwu_ask_res tar where tar.asr_text is null;"""
)
return
pool
.
select_all
(
sql
,
None
)
def
update_tingwu_ask_res_task_id
(
id
:
int
,
task_id
:
str
):
sql
=
(
f
"""UPDATE tingwu_ask_res SET task_id =
%
s WHERE id =
%
s;"""
)
return
pool
.
select_all
(
sql
,
(
task_id
,
id
))
def
update_tingwu_ask_res_asr_text
(
task_id
:
str
,
asr_text
:
str
):
sql
=
(
f
"""UPDATE tingwu_ask_res SET asr_text =
%
s WHERE task_id =
%
s;"""
)
return
pool
.
select_all
(
sql
,
(
asr_text
,
task_id
))
mysql_service/mysql_pool.py
View file @
5f29a5c
...
@@ -45,7 +45,10 @@ class ConnPool:
...
@@ -45,7 +45,10 @@ class ConnPool:
def
select_all
(
self
,
sql
,
args
):
def
select_all
(
self
,
sql
,
args
):
"""查询多条数据"""
"""查询多条数据"""
log
.
info
(
f
"execute_select_all sql:{sql}"
%
args
)
if
args
is
None
:
log
.
info
(
f
"execute_select_all sql:{sql}"
)
else
:
log
.
info
(
f
"execute_select_all sql:{sql}"
%
args
)
conn
,
cursor
=
self
.
open
()
conn
,
cursor
=
self
.
open
()
cursor
.
execute
(
sql
,
args
)
cursor
.
execute
(
sql
,
args
)
result
=
cursor
.
fetchall
()
result
=
cursor
.
fetchall
()
...
...
utils/ali/test_03_car.py
View file @
5f29a5c
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
import
os
import
os
import
json
import
json
import
datetime
import
datetime
import
traceback
import
requests
import
requests
import
time
import
time
...
@@ -121,6 +123,37 @@ def dealResultJson(contentUrl, TaskId):
...
@@ -121,6 +123,37 @@ def dealResultJson(contentUrl, TaskId):
return
text_list
return
text_list
def
dealResultStandardJson
(
contentUrl
,
TaskId
):
contentResponse
=
requests
.
get
(
contentUrl
)
contentResponseJson
=
contentResponse
.
json
()
paragraphsArray
=
contentResponseJson
[
'Transcription'
][
'Paragraphs'
]
text_list
=
[]
for
paraItem
in
paragraphsArray
:
SpeakerId
=
paraItem
.
get
(
'SpeakerId'
)
wordsArray
=
paraItem
[
'Words'
]
curSentenceId
=
1
index
=
0
wordLine
=
''
for
wordItem
in
wordsArray
:
sentenceId
=
wordItem
[
'SentenceId'
]
if
curSentenceId
!=
sentenceId
or
index
==
0
:
# if wordLine != '':
# # print(wordLine)
# text_list.append(wordLine)
curSentenceId
=
sentenceId
seconds
=
wordItem
[
'Start'
]
//
1000
lineTime
=
str
(
datetime
.
timedelta
(
seconds
=
seconds
))
if
len
(
lineTime
)
<
8
:
lineTime
=
'0'
+
lineTime
# wordLine = f'[{lineTime}] {SpeakerId}:'
# wordLine = f'{SpeakerId}:'
wordLine
=
wordLine
+
wordItem
[
'Text'
]
index
+=
1
# print(wordLine)
text_list
.
append
({
"role"
:
SpeakerId
,
"content"
:
wordLine
})
return
text_list
def
submitTask
(
fileUrl
):
def
submitTask
(
fileUrl
):
request
=
create_common_request
(
'tingwu.cn-beijing.aliyuncs.com'
,
'2023-09-30'
,
'https'
,
'PUT'
,
request
=
create_common_request
(
'tingwu.cn-beijing.aliyuncs.com'
,
'2023-09-30'
,
'https'
,
'PUT'
,
'/openapi/tingwu/v2/tasks'
)
'/openapi/tingwu/v2/tasks'
)
...
@@ -160,7 +193,8 @@ def dealTaskResult(TaskId):
...
@@ -160,7 +193,8 @@ def dealTaskResult(TaskId):
taskStatus
=
responseJson
[
'Data'
][
'TaskStatus'
]
taskStatus
=
responseJson
[
'Data'
][
'TaskStatus'
]
if
taskStatus
==
'COMPLETED'
:
if
taskStatus
==
'COMPLETED'
:
resultUrl
=
responseJson
[
'Data'
][
'Result'
][
'Transcription'
]
resultUrl
=
responseJson
[
'Data'
][
'Result'
][
'Transcription'
]
text_list
=
dealResultJson
(
resultUrl
,
TaskId
)
# text_list = dealResultJson(resultUrl, TaskId)
text_list
=
dealResultStandardJson
(
resultUrl
,
TaskId
)
return
text_list
return
text_list
time
.
sleep
(
10
)
time
.
sleep
(
10
)
...
@@ -185,6 +219,7 @@ client = AcsClient(region_id='cn-beijing', credential=credentials)
...
@@ -185,6 +219,7 @@ client = AcsClient(region_id='cn-beijing', credential=credentials)
base_path
=
"D:/software/python/project/funasr_web/audios/0903/"
base_path
=
"D:/software/python/project/funasr_web/audios/0903/"
txt_path
=
"D:/software/python/project/funasr_web/audios/11111.txt"
txt_path
=
"D:/software/python/project/funasr_web/audios/11111.txt"
def
run_file
():
def
run_file
():
with
open
(
txt_path
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
with
open
(
txt_path
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
for
index
,
line
in
enumerate
(
file
,
1
):
for
index
,
line
in
enumerate
(
file
,
1
):
...
@@ -198,6 +233,7 @@ def run_file():
...
@@ -198,6 +233,7 @@ def run_file():
text_list
=
dealTaskResult
(
taskId
)
text_list
=
dealTaskResult
(
taskId
)
write_file
(
text_list
,
f
"{base_path}{name}.txt"
)
write_file
(
text_list
,
f
"{base_path}{name}.txt"
)
def
run_simple
(
fileUrl
,
name
=
None
):
def
run_simple
(
fileUrl
,
name
=
None
):
taskId
=
submitTask
(
fileUrl
)
taskId
=
submitTask
(
fileUrl
)
# taskId = 'd80649120bc04d10892f99d70082c194'
# taskId = 'd80649120bc04d10892f99d70082c194'
...
@@ -205,4 +241,34 @@ def run_simple(fileUrl, name=None):
...
@@ -205,4 +241,34 @@ def run_simple(fileUrl, name=None):
text_list
=
dealTaskResult
(
taskId
)
text_list
=
dealTaskResult
(
taskId
)
write_file
(
text_list
,
f
"{base_path}{name}.txt"
)
write_file
(
text_list
,
f
"{base_path}{name}.txt"
)
run_simple
(
"https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_172612704155017261137765681.mp3"
,
name
=
"merged_172612704155017261137765681"
)
\ No newline at end of file
\ No newline at end of file
def
run_table
():
from
mysql_service
import
funasr_db
sql_res
=
funasr_db
.
select_tingwu_ask_res
()
start_time
=
time
.
time
()
for
data
in
sql_res
:
try
:
task_id
=
submitTask
(
data
.
get
(
'recording_url'
))
# text_list = dealTaskResult(task_id)
# print(json.dumps(text_list, ensure_ascii=False, indent=4))
funasr_db
.
update_tingwu_ask_res_task_id
(
data
.
get
(
'id'
),
task_id
)
except
Exception
as
e
:
traceback
.
print_exc
()
continue
print
(
f
"submitTask Execution time: {time.time() - start_time:.4f} seconds"
)
sql_res2
=
funasr_db
.
select_tingwu_ask_res
()
for
data
in
sql_res2
:
try
:
start_time2
=
time
.
time
()
task_id
=
data
.
get
(
'task_id'
)
text_list
=
dealTaskResult
(
task_id
)
# print(json.dumps(text_list, ensure_ascii=False, indent=4))
funasr_db
.
update_tingwu_ask_res_asr_text
(
task_id
,
json
.
dumps
(
text_list
,
ensure_ascii
=
False
,
indent
=
4
))
print
(
f
"task_id:{task_id} Execution time: {time.time() - start_time2:.4f} seconds"
)
except
Exception
as
e
:
traceback
.
print_exc
()
continue
# run_simple("https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/1_1120_赛力斯、平安智驾项目对接会议.m4a",name="对接会议")
run_table
()
utils/finetune.py
View file @
5f29a5c
...
@@ -382,4 +382,4 @@ def down_file_upload_release(table_name):
...
@@ -382,4 +382,4 @@ def down_file_upload_release(table_name):
print
(
sql
)
print
(
sql
)
upload_file
(
"1_1120_赛力斯、平安智驾项目对接会议.m4a"
,
"D:
\\
software
\\
python
\\
project
\\
funasr_web
\\
log
\\
1_1120_赛力斯、平安智驾项目对接会议.m4a"
)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment