TCP套接字编程,客户端出现ConnectionResetError:[Errno 104] Connection reset by peer

在TCP套接字的编程中,服务端报错为:
服务端报错截图
客户端的报错为:
客户端报错截图
经过检查发现,是由于服务器端的recv()方法,没有写缓冲区大小参数导致
服务端错误代码位置截图
解决办法:
在服务端的recv()方法内写上参数,比如 recv_data = service_client_socket.recv(1024)

在一台离网服务器上,出现此报错,请分析原因 ConnectionResetError: [Errno 104] Connection reset by peer 代码: import os import json import whisper # 假设您已经将文本文件内容读取到数组中 # lines = [ # "IC0936W0001\t第六十一集", # "IC0936W0002\t第六十二集", # # ... 其他行 # ] # 1. 构建映射字典 f=open("/home/tcenterlmx/iOS/data/trans.txt","r",encoding="utf-8") lines=f.readlines() transcript_map = {} for line in lines: parts = line.strip().split('\t') if len(parts) >= 2: file_id = parts[0] # 如 "IC0936W0001" text = parts[1] # 如 "第六十一集" transcript_map[file_id] = text # 2. 音频文件夹路径(假设音频文件在此目录下) audio_dir = "/home/tcenterlmx/iOS/data/wav/C0936" # 3. 直接生成manifest文件 manifest_path = "whisper_manifest.jsonl" with open(manifest_path, 'w', encoding='utf-8') as manifest: # 遍历音频文件夹中的所有wav文件 for filename in os.listdir(audio_dir): if filename.lower().endswith('.wav'): # 提取文件名ID(不含扩展名) file_id = os.path.splitext(filename)[0] # 检查是否有对应的转录文本 if file_id in transcript_map: audio_path = os.path.join(audio_dir, filename) text = transcript_map[file_id] # 写入JSONL记录 record = { "audio_filepath": audio_path, "text": text, "id": file_id } manifest.write(json.dumps(record, ensure_ascii=False) + '\n') else: print(f"警告: 文件 {filename} 没有对应的转录文本") print(f"已生成manifest文件: {manifest_path}") print(f"包含 {len(transcript_map)} 个样本") # 加载模型 model = whisper.load_model("large-v3") # 读取manifest文件 with open("whisper_manifest.jsonl", "r", encoding="utf-8") as f: for line in f: data = json.loads(line) audio_path = data["audio_filepath"] true_text = data["text"] # 使用Whisper进行转录 result = model.transcribe(audio_path, language="zh") predicted_text = result["text"] # 对比结果(可根据需要保存到文件) print(f"文件: {os.path.basename(audio_path)}") print(f"真实文本: {true_text}") print(f"预测文本: {predicted_text}") print(f"匹配: {true_text == predicted_text}\n")
最新发布
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值