text stringlengths 1 93.6k |
|---|
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
|
# # --------------------------------------
|
# # -------- SenceVoice 语音识别 --模型加载-----
|
# model_dir = r"E:\2_PYTHON\Project\GPT\QWen\pretrained_models\SenseVoiceSmall"
|
# model_senceVoice = AutoModel( model=model_dir, trust_remote_code=True, )
|
# folder_path = "./Test_QWen2_VL/"
|
# def Inference(TEMP_VIDEO_FILE=f"{OUTPUT_DIR}/video_0.avi", TEMP_AUDIO_FILE=f"{OUTPUT_DIR}/audio_0.wav"):
|
# file_path = os.path.join(folder_path, "captured_image.jpg") # 设置保存路径
|
# cap = cv2.VideoCapture(TEMP_VIDEO_FILE)
|
# total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
# frame_index = int(total_frames // 2)
|
# # 设置视频帧位置
|
# cap.set(cv2.CAP_PROP_POS_FRAMES, frame_index)
|
# ret, frame = cap.read()
|
# if not ret:
|
# print(f"无法读取帧索引 {frame_index}")
|
# else:
|
# # 显示帧
|
# cv2.imwrite(file_path, frame)
|
# # cv2.imshow(f"Frame {frame_index}", frame)
|
# # -------- SenceVoice 推理 ---------
|
# input_file = (TEMP_AUDIO_FILE)
|
# res = model_senceVoice.generate(
|
# input=input_file,
|
# cache={},
|
# language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
|
# use_itn=False,
|
# )
|
# prompt = res[0]['text'].split(">")[-1]
|
# # ---------SenceVoice --end----------
|
# # -------- QWen2-VL 模型推理 ---------
|
# messages = [
|
# {
|
# "role": "user",
|
# "content": [
|
# {
|
# "type": "image",
|
# "image": f"{file_path}",
|
# },
|
# {"type": "text", "text": f"{prompt}"},
|
# ],
|
# }
|
# ]
|
# # Preparation for inference
|
# text = processor.apply_chat_template(
|
# messages, tokenize=False, add_generation_prompt=True
|
# )
|
# image_inputs, video_inputs = process_vision_info(messages)
|
# inputs = processor(
|
# text=[text],
|
# images=image_inputs,
|
# videos=video_inputs,
|
# padding=True,
|
# return_tensors="pt",
|
# )
|
# inputs = inputs.to("cuda")
|
# # Inference: Generation of the output
|
# generated_ids = model.generate(**inputs, max_new_tokens=128)
|
# generated_ids_trimmed = [
|
# out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
# ]
|
# output_text = processor.batch_decode(
|
# generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
# )
|
# print(output_text)
|
# # 输入文本
|
# text = output_text[0]
|
# # asyncio.run(amain(text, "zh-CN-YunxiaNeural", os.path.join(folder_path,"sft_0.mp3")))
|
# # play_audio(f'{folder_path}/sft_0.mp3')
|
# asyncio.run(amain(text, "zh-CN-XiaoyiNeural", os.path.join(folder_path,"sft_0.mp3")))
|
# play_audio(f'{folder_path}/sft_0.mp3')
|
# # asyncio.run(amain(text, "zh-CN-YunjianNeural", os.path.join(folder_path,"sft_0.mp3")))
|
# # play_audio(f'{folder_path}/sft_0.mp3')
|
# # asyncio.run(amain(text, "zh-CN-shaanxi-XiaoniNeural", os.path.join(folder_path,"sft_0.mp3")))
|
# # play_audio(f'{folder_path}/sft_0.mp3')
|
# 主函数
|
if __name__ == "__main__":
|
try:
|
# 启动音视频录制线程
|
audio_thread = threading.Thread(target=audio_recorder)
|
video_thread = threading.Thread(target=video_recorder)
|
audio_thread.start()
|
video_thread.start()
|
print("按 Ctrl+C 停止录制")
|
while True:
|
time.sleep(1)
|
except KeyboardInterrupt:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.