【每日学点鸿蒙知识】tensorflowlite编译、音频编码线程、沉浸式状态栏、TextArea最大字节数限制等

1、如何编译Tensorflow lite库?

之前项目基于tflite推理引擎做人脸识别的功能,鸿蒙侧如何复用tflite模型?

tflite对Android和iOS本身支配了GPU支持,但是鸿蒙侧目前并没有,鸿蒙提供了自己的推理引擎,而且支持将tflite模型转换为鸿蒙推理引擎模型,建议使用鸿蒙官方方案。

2、音频编码需要单独设置线程吗?

编码可以不另外起线程,系统的编解码会起线程。写文件是应用自己根据自身需求另外起线程处理。

3、创建音频编码器配置参数报错

复制代码
// 通过 codecname 创建编码器
OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_MPEG, true);
const char *name = OH_AVCapability_GetName(capability);
audioEnc_ = OH_AudioCodec_CreateByName(name);

 // 配置最大输入长度, 每帧音频数据的大小(可选)
    uint32_t DEFAULT_MAX_INPUT_SIZE = inSamplerate * TIME_PER_FRAME * inChannel * sizeof(short); // aac
    OH_AVFormat *format = OH_AVFormat_Create();
    // 写入format
    OH_AVFormat_SetIntValue(format,OH_MD_KEY_AUD_CHANNEL_COUNT, inChannel);
    OH_AVFormat_SetIntValue(format,OH_MD_KEY_AUD_SAMPLE_RATE, inSamplerate);
    OH_AVFormat_SetLongValue(format,OH_MD_KEY_BITRATE, outBitrate);
    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_FORMAT);
    OH_AVFormat_SetLongValue(format,OH_MD_KEY_CHANNEL_LAYOUT, CHANNEL_LAYOUT);
//     OH_AVFormat_SetIntValue(format,OH_MD_KEY_MAX_INPUT_SIZE, DEFAULT_MAX_INPUT_SIZE);
    // 配置编码器
    ret = OH_AudioCodec_Configure(audioEnc_, format);
    if (ret != AV_ERR_OK) {
        printLog("configure failed");
    }

传入参数:采样率48000, 声道数2, 码率128,ret返回为3:

复制代码
/**  
 * @error invalid argument. */
AV_ERR_INVALID_VAL = 3,

输出码率设置太低,改成128000。

4、如何设置沉浸式状态栏?

在UIAbility onWindowStageCreate方法中设置沉浸式状态栏:

复制代码
async function enterImmersion(windowClass: window.Window) {  
  // 设置窗口布局为沉浸式布局  
  await windowClass.setWindowLayoutFullScreen(true)  
}

async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {  
  await enterImmersion(windowClass)  
}

5、如何设置TextArea最大允许输入字节数?

可以在onChange回调中,自行计算当前输入的字节长度(参考示例如下),再与服务端的最大字节长度做对比,若超出则禁止输入:

复制代码
export function CalUtf8BytesLen(str: string): number {  
  let length = 0;  
  for (const char of str) {  
    let code = char.charCodeAt(0);  
    if (code <= 0x7f) {  
      length += 1; // 0xxxxxxx  
    } else if (code <= 0x7ff) {  
      length += 2; // 110xxxxx 10xxxxxx  
    } else if (code >= 0xd800 && code <= 0xdfff) {  
      // surrogate pair  
      if (char.length === 2) {  
        code = (char.charCodeAt(0) - 0xd800) * 0x400 + char.charCodeAt(1) - 0xdc00 + 0x10000;  
        length += 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx  
      } else {  
        throw new Error('Invalid surrogate pair');  
      }  
    } else {  
      length += 3; // 1110xxxx 10xxxxxx 10xxxxxx  
    }  
  }  return length;  
}
相关推荐
半路下车18 分钟前
【Harmony OS 5】DevEco Testing赋能智慧教育
harmonyos·arkts
libo_202527 分钟前
HarmonyOS5 灰度发布:通过AGC控制台分阶段更新Uniapp混合应用
harmonyos
libo_202528 分钟前
自动化测试:将Uniapp页面注入HarmonyOS5 UITest框架
harmonyos
libo_202528 分钟前
HarmonyOS5 Uniapp+OpenHarmony标准设备适配指南
harmonyos
libo_202529 分钟前
HarmonyOS5 内存优化:用DevEco Studio Profiler分析Uniapp混合栈泄漏
harmonyos
libo_202532 分钟前
AI能力整合:在Uniapp中调用HarmonyOS5 HiAI Kit的图像识别
harmonyos
libo_202532 分钟前
HarmonyOS5 Uniapp应用上架AppGallery全流程:从签名到过审避坑指南
harmonyos
Tianyanxiao2 小时前
华为×小鹏战略合作:破局智能驾驶深水区的商业逻辑深度解析
大数据·人工智能·经验分享·华为·金融·数据分析
程序员小刘2 小时前
【HarmonyOS 5】运动健康开发实践介绍以及详细案例
华为·harmonyos