yuxiang1990's picture
update
25c1213
raw
history blame contribute delete
No virus
3.2 kB
import matplotlib
matplotlib.use('TkAgg')
import gradio as gr
from time import time
import soundfile
import os
import numpy as np
names = ["助手小技,", "小技助手,", ""]
actions = ["显示", "隐藏", "全部显示", "单独显示", "仅显示", "清除", "全部清除", "打开", "关闭"]
texts1 = ['肝段', "肺段", "肝脏", "左肺", "右肺", "左三叶", "右三叶",
"病灶", "结节", "肝肿瘤",
"脉管", "支气管", "动脉", "静脉", "肺动脉", "肺气管", "肺静脉", "肝静脉", "门静脉", "下腔静脉", "上腔静脉", "主动脉", "食管", "胆囊管",
"胆囊", "纵膈", "骨骼", "骨头", "心脏"]
texts2_1 = ["左肺", "右肺"]
texts2_2 = ["尖段", "后段", "前段", "外侧段", "内侧段", "背段", "内基底段", "前基底段", "外基底段", "后基底段"]
texts3_1 = ["肝脏", "右肺"]
texts3_2 = ["左外叶上段", "左外叶下段", "左内叶上段", "左内叶下段", "右前叶下段", "右后叶下段", "右后叶上段", "右前叶上段", "尾状叶"]
def update_hotapi():
if np.random.random() > 0.6:
times = np.random.randint(1, 6)
new_text = np.random.choice(names) + np.random.choice(actions) + ",".join(np.random.choice(texts1, size=times, replace=False))
else:
if np.random.random() > 0.5:
new_text = np.random.choice(names) + np.random.choice(actions) + np.random.choice(texts2_1) + np.random.choice(texts2_2)
else:
new_text = np.random.choice(names) + np.random.choice(actions) + np.random.choice(texts3_1) + np.random.choice(texts3_2)
return new_text
cnt_dict = {}
def hot_save(audio_list, text, prefix_text):
global cnt_dict
if prefix_text not in cnt_dict:
cnt_dict[prefix_text] = 0
print("hot save start!!!!!")
rate, audio_arr = audio_list
wav_path = "./{}-{}-{}-cnt{}.mp3".format(prefix_text, text, str(int(time())), cnt_dict[prefix_text]))
soundfile.write(wav_path, data=audio_arr, samplerate=rate)
update_text = update_hotapi()
cnt_dict[prefix_text] += 1
print("hot save done!!!!!")
return update_text, None, cnt_dict[prefix_text]
with gr.Blocks() as demo:
gr.Markdown("## Smars-AI 三维重建语音**无约束**录制助手")
gr.Markdown("#### 流程:\n"
"- step1: 输入待采集人姓名:(随意,简称就行)\n"
"- step2: 点击`record`/`录制`, 按照`热词采集`说话,然后点击`stop`, 因可能存在网络延迟,等待1~2s\n"
"- step3: 点击`保存录音`,如果遇到error,再次保存; \n")
with gr.Group():
text = gr.Textbox(label="热词采集:(动态随机更新)", min_width=100, value="小技助手")
prefix_text = gr.Textbox(label="采集人,请输入:", min_width=100, value='anonymous')
slider = gr.Slider(minimum=0, maximum=66, value=0, step=1, label="录制计数", scale=1, interactive=False)
audio = gr.Audio(sources=["microphone"])
save_buttom = gr.Button('保存录音')
save_buttom.click(hot_save, inputs=[audio, text, prefix_text], outputs=[text, audio, slider])
demo.launch()