河北京电电力建设有限公司网站,html网页制作背景图片,如何做国外外贸网站,天津品牌网站设计前言
“接口也是口#xff0c;算法也是算”#xff0c;综合来看就是口算#xff01; 看到全网都在炸鱼也忍不住来玩一玩… 参考了大佬的OCR版#xff0c;试用后发现影响速度的最大卡点并不是识别速度等#xff0c;而是““由于检测异常导致的等待”。 基于体验几局的感受…前言
“接口也是口算法也是算”综合来看就是口算 看到全网都在炸鱼也忍不住来玩一玩… 参考了大佬的OCR版试用后发现影响速度的最大卡点并不是识别速度等而是““由于检测异常导致的等待”。 基于体验几局的感受——输入对了可以极速跳题、答题成功会有提示音便将思路放到了从音量检测入手。
实现
思路大致几点—— 1、输入对了可以极速跳题。 2、答题成功会有提示音。 3、目前没有看到过输入“”的场景仅有大于和小于。 基于上述三点暴力作答所需猜测的情况也只有两种且作答成功后可快速进行下一题减少卡顿理论可行。 因此尝试不通过ORC识别或其他方式来判断题目作答正确而是采取“是否曝出了提示音“”来判断是否作答正确。
流程大致为 1、作答符号为。
如果有提示音短停留继续作答。如果没有提示音 长停留继续作答。 2、切换作答符号为另一个。 由此循环往复…
代码
需自行安装虚拟声卡用于让Python检测声音。
import pyautogui
import time
import numpy as np
import pyaudio
from pynput.mouse import Controller, Button
from pynput.keyboard import Listener, Key# 初始化鼠标控制器
mouse Controller()# 全局变量控制绘制状态
running False
prev_volume 0 # 上一个音量值def log_message(message):记录日志消息current_time time.strftime(%Y-%m-%d %H:%M:%S, time.localtime())print(f[{current_time}] {message})def draw_symbol(symbol):绘制符号screen_width, screen_height pyautogui.size()x int(screen_width * 0.4) # 水平居中y int(screen_height * 0.7) # 将 y 坐标设置为屏幕高度的 70%duration 0.03 # 每条线的持续时间rect_size 40 # 控制绘制符号的大小线条长度的控制if symbol :# 绘制 符号mouse.position (x, y)mouse.press(Button.left)mouse.move(rect_size, rect_size) # 右下斜线time.sleep(duration)mouse.move(-rect_size, rect_size) # 左下斜线time.sleep(duration)mouse.release(Button.left)log_message(执行了绘制 符号 操作)elif symbol :# 绘制 符号mouse.position (x, y)mouse.press(Button.left)mouse.move(-rect_size, rect_size) # 左下斜线time.sleep(duration)mouse.move(rect_size, rect_size) # 右下斜线time.sleep(duration)mouse.release(Button.left)log_message(执行了绘制 符号 操作)def list_audio_devices():列出可用的音频输入设备p pyaudio.PyAudio()log_message(可用的音频设备:)for i in range(p.get_device_count()):info p.get_device_info_by_index(i)log_message(f设备 {i}: {info[name]} - {输入 if info[maxInputChannels] 0 else 输出})p.terminate()def get_supported_sample_rates(device_index):获取指定设备支持的采样率p pyaudio.PyAudio()device_info p.get_device_info_by_index(device_index)log_message(f设备 {device_index} ({device_info[name]}) 支持的采样率: {device_info[defaultSampleRate]})p.terminate()return int(device_info[defaultSampleRate])def detect_system_sound(threshold1000, device_index24): # 使用设备索引 24检测系统声音并返回是否检测到突然增加的声音global prev_volume # 声明使用全局变量chunk 1024 # 每次读取的音频块大小sample_rate get_supported_sample_rates(device_index) # 获取支持的采样率p pyaudio.PyAudio()# 打开音频流确保输入设备是虚拟音频设备stream p.open(formatpyaudio.paInt16, channels1,ratesample_rate, inputTrue,frames_per_bufferchunk, input_device_indexdevice_index)audio_data stream.read(chunk)audio_data_np np.frombuffer(audio_data, dtypenp.int16)volume_norm np.linalg.norm(audio_data_np) / np.sqrt(chunk) # 计算音量RMSstream.stop_stream()stream.close()p.terminate()log_message(f当前音量{volume_norm:.2f}) # 打印当前音量以调试# 检测音量的突然增加if volume_norm prev_volume threshold:prev_volume volume_norm # 更新上一个音量值return True # 检测到声音突增else:prev_volume volume_norm # 更新上一个音量值return False # 未检测到声音突增def toggle_running(key):切换运行状态global runningif key Key.enter: # 当按下 Enter 键时切换状态running not runningif running:log_message(绘图已启动...)else:log_message(绘图已停止。)def main():global runninglog_message(按 Enter 键启动或停止绘图...)i 0# 列出可用的音频设备list_audio_devices()# 启动键盘监听with Listener(on_presstoggle_running) as listener:while True:if running:# 检测声音sound_detected detect_system_sound()if sound_detected:log_message(有检测到声音突增)time.sleep(0.2) # 如果检测到声音突增等待 0.2 秒else:log_message(未检测到声音突增等待 1 秒...)time.sleep(0.8) # 如果未检测到声音等待 1 秒# 绘制 符号if i % 2:draw_symbol()else:draw_symbol()i 1# 换行分隔log_message()time.sleep(0.1) # 避免占用过多 CPU 资源if __name__ __main__:main()
优化点。
1、由于小猿口算的Bug——即背景音乐无法关闭。导致检测声音突增并不是那么准确。同时吐槽一下小猿官方没有对用户名违禁进行检测吗头像用户名均sex居然可以过审难以想象。 2、模拟器产生声音 - Python检测到变化会有一定的延迟。
综合测试来看感觉可能并不比单纯的暴力快多少因此此尝试更多的还是——整活。