美文网首页
autojs哪里想读点哪里

autojs哪里想读点哪里

作者: 牙叔教程 | 来源:发表于2021-04-24 20:29 被阅读0次

    牙叔教程 简单易学

    使用场景

    需要语音朗读的图片

    autojs版本

    autojs版本.png

    get知识点

    1. 浩然ocr
    2. 讯飞语音合成webapi
    3. Hmacsha256加密
    4. base64
    5. MediaPlayer
    6. 安卓自带语音TTS
    7. 悬浮窗
    8. loadsh
    9. events.broadcast

    代码简介

    1. 监听用户点击, 使用的是悬浮窗, 用户点击屏幕, 实际上点到了悬浮窗上
    2. 语音有三种
    • 讯飞
    • 百度
    • 手机自带TTS
    3. 提取离手指最近的文字块, 先取上面, 再取下面, 最后排序

    代码详解

    1, 保持悬浮窗不被关闭
    setInterval(function () {}, 1000);
    
    2. 停止别的脚本
    engines.all().map((ScriptEngine) => {
      if (engines.myEngine().toString() !== ScriptEngine.toString()) {
        ScriptEngine.forceStop();
      }
    });
    
    3. 请求截图
    if (!requestScreenCapture()) {
      toast("请求截图失败");
      exit();
    }
    
    4. 所有功能全部模块化, 方便复用
    let _ = require("lodash");
    let 创建全屏悬浮窗 = require("./创建全屏悬浮窗");
    let 设置点击监听 = require("./设置点击监听");
    let 语音 = require("./语音");
    let 提取离手指最近的文字块集合 = require("./提取离手指最近的文字块集合");
    let ocr = require("./ocr");
    
    5. 从点击到朗读文字的大致步骤
    events.broadcast.on("点击的坐标", function (点击的坐标) {
      let filePath = 截屏();
      let textBlockList = ocr(filePath);
      let x = 点击的坐标.x;
      let y = 点击的坐标.y;
      let arr = 提取离手指最近的文字块集合(x, y, textBlockList);
      if (arr.length < 1) {
        toastLog("屏幕上没有文字");
      } else {
        var len = arr.length;
        let dataList = [];
        for (var i = 0; i < len; i++) {
          dataList.push(arr[i].labelName);
        }
        let data = dataList.join("\n");
        语音(data);
        // 语音(data, "讯飞");
        // 语音(data, "百度");
      }
    });
    
    6. 浩然ocr识别文字
    let ocr0 = $plugins.load("com.hraps.ocr");
    
    let img = images.read(imgPath);
    let bitmap = img.getBitmap();
    let results = ocr0.detect(bitmap, 1);
    

    参考文章

    声明

    部分内容来自网络

    给我个面子小图.jpg

    相关文章

      网友评论

          本文标题:autojs哪里想读点哪里

          本文链接:https://www.haomeiwen.com/subject/qwilrltx.html