str_word_count() 函数

探讨算法标注工程师核心技能,深入解析人工智能领域数据标注流程与最佳实践,提升算法训练质量。
void Audio_Play(const char *str) { char used_flags[200] = {0}; // 标记哪些字符已被匹配 match_info_t match_list[MAX_VOICE_NUM] = {0}; int iRet = 0,num = 0,flag = 0,i = 0; volatile int match_count = 0; char output[12] = {0},str_num[1]={0}; int outlen = 0; int Voice_Num = 0; voice_file_list_t *pVoiceFileList = NULL; uint8_t *pVoiceFileBuff = NULL; EM_TTS_PLAY_STATE emPlayState; const char *key_word_1[] = {"当前电压为","烤机时间最大时间", "8秒内","第","wifi测试成功","GSM测试成功", "充电测试","wifi测试","断码屏", "GSM测试","WIFI测试","信号强度", "当前信号","正在使用4G网络","正在使用2G网络"}; const char *key_word_2[] = {"烤机时间最小5分钟","音量加", "按音量调整时间,功能键确认","指示灯测试","断码屏测试", "音量减","功能键","关机键","工装未测试","分钟","伏", "轮烤机","是否正常","未按下","失败,按功能键重试"}; pVoiceFileBuff = (uint8_t *)malloc(sizeof(voice_file_list_t) + (MAX_VOICE_NUM * sizeof(voice_file_play_info_t))); pVoiceFileList = (voice_file_list_t *)pVoiceFileBuff; if(!pVoiceFileBuff){ return ; } memset(pVoiceFileBuff, 0, (sizeof(voice_file_list_t) + (MAX_VOICE_NUM * sizeof(voice_file_play_info_t)))); pVoiceFileList = (voice_file_list_t *)pVoiceFileBuff; pVoiceFileList->voiceFileInfo = (voice_file_play_info_t *)&pVoiceFileBuff[sizeof(voice_file_list_t)]; PLATFORM_DEBUG("[Audio_Play] str: %s\n", str); if(strstr(str,"按键测试失败,按功能键重试") != NULL || strstr(str,"GSM测试失败,按功能键重试") != NULL){ iRet = API_VoiceFile_GetPlayInfo("按键测试", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} iRet = API_VoiceFile_GetPlayInfo("失败,按功能键重试", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} goto loop; } if(strstr(str,"GSM测试失败,按功能键重试") != NULL){ iRet = API_VoiceFile_GetPlayInfo("GSM测试", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} iRet = API_VoiceFile_GetPlayInfo("失败,按功能键重试", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} goto loop; } if(strstr(str,"wifi测试失败,按功能键重试") != NULL){ iRet = API_VoiceFile_GetPlayInfo("wifi测试", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} iRet = API_VoiceFile_GetPlayInfo("失败,按功能键重试", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} goto loop; } if(strstr(str,"测试结束") != NULL){ iRet = API_VoiceFile_GetPlayInfo("测试", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} iRet = API_VoiceFile_GetPlayInfo("结束", &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0){ return;} goto loop; } #if 0 for(i = 0;i < sizeof(key_word_1)/sizeof(key_word_1[0]); i++){ const char *p = strstr(str,key_word_1[i]); PLATFORM_DEBUG("\np====%d\n",p); if(p){ match_list[match_count].position = p - str; PLATFORM_DEBUG("关键词1的match_list[match_count].position %d\n",match_list[match_count].position); match_list[match_count].text = key_word_1[i]; PLATFORM_DEBUG("key_word_1[i]:%s\n",key_word_1[i]); match_list[match_count].is_keyword = 1; match_count++; } } for(i = 0;i < sizeof(key_word_2)/sizeof(key_word_2[0]); i++){ const char *p = strstr(str,key_word_2[i]); PLATFORM_DEBUG("\np====%d\n",p); if(p){ match_list[match_count].position = p - str; PLATFORM_DEBUG("关键词2的match_list[match_count].position %d\n",match_list[match_count].position); match_list[match_count].text = key_word_2[i]; match_list[match_count].is_keyword = 1; match_count++; } } #else for (int i = 0; i < sizeof(key_word_1) / sizeof(key_word_1[0]); i++) { const char *p = strstr(str, key_word_1[i]); if(strcmp(str,key_word_1[i]) == 0){ match_count = 0; break; } #if 0 if (p) { int pos = p - str; int len = strlen(key_word_1[i]); int overlap = 0; for (int j = 0; j < len; j++) { if (used_flags[pos + j]) { overlap = 1; break; } } if (overlap) continue; match_list[match_count].position = pos; match_list[match_count].text = key_word_1[i]; PLATFORM_DEBUG("关键词1的match_list[match_count].position %d\n",match_list[match_count].position); match_list[match_count].is_keyword = 1; match_count++; for (int j = 0; j < len; j++) { used_flags[pos + j] = 1; } } #else if(p){ match_list[match_count].position = p - str; //PLATFORM_DEBUG("关键词1的match_list[match_count].position %d\n",match_list[match_count].position); match_list[match_count].text = key_word_1[i]; // PLATFORM_DEBUG("key_word_1[i]:%s\n",key_word_1[i]); match_list[match_count].is_keyword = 1; match_count++; } } #endif // 匹配关键词 key_word_2 for (int i = 0; i < sizeof(key_word_2) / sizeof(key_word_2[0]); i++) { const char *p = strstr(str, key_word_2[i]); if(strcmp(str,key_word_2[i]) == 0){ match_count = 0; break; } if (p) { int pos = p - str; int len = strlen(key_word_2[i]); int overlap = 0; for (int j = 0; j < len; j++) { if (used_flags[pos + j]) { overlap = 1; break; } } if (overlap) continue; match_list[match_count].position = pos; match_list[match_count].text = key_word_2[i]; //PLATFORM_DEBUG("关键词2的match_list[match_count].position %d\n",match_list[match_count].position); match_list[match_count].is_keyword = 1; match_count++; for (int j = 0; j < len; j++) { used_flags[pos + j] = 1; } } } #endif for(i = 0;i < strlen(str);i++){ if ((isdigit((unsigned char)str[i]) || str[i] == '.' || str[i] == '-') && strstr(str, "正在使用4G网络") == NULL && strstr(str, "正在使用2G网络") == NULL && strstr(str, "烤机时间最小5分钟") == NULL && strstr(str, "8秒内") == NULL) { // 可以提取数字 match_list[match_count].position = i; PLATFORM_DEBUG("数字match_list[match_count].position %d\n",match_list[match_count].position); match_list[match_count].text = Match_num(str[i]); match_list[match_count].is_keyword = 0; match_count++; } } PLATFORM_DEBUG("match_count%d\n",match_count); qsort(match_list, match_count, sizeof(match_info_t), compare_match_info); if(match_count == 0){ iRet = API_VoiceFile_GetPlayInfo(str, &pVoiceFileList->voiceFileInfo[Voice_Num++]); if (iRet != 0) return; goto loop; } for (int i = 0; i < match_count; i++) { if (Voice_Num >= MAX_VOICE_NUM) return; // 防止越界 iRet = API_VoiceFile_GetPlayInfo(match_list[i].text, &pVoiceFileList->voiceFileInfo[Voice_Num++]); PLATFORM_DEBUG("match_list[i].text %s voice_num %d iRet:=%d\n",match_list[i].text,Voice_Num,iRet); if (iRet != 0) return; } loop: pVoiceFileList->voiceFileNum =Voice_Num; PLATFORM_DEBUG("Voice_Num %d\n",Voice_Num); iRet = API_VoiceFile_Play_FileList(pVoiceFileList); PLATFORM_DEBUG("API_VoiceFile_Play_FileList %d \n",iRet); if(iRet == API_OK){ while(1){ API_Sys_TaskDelay(100); iRet = API_Tts_CheckState(&emPlayState); PLATFORM_DEBUG("API_Tts_CheckState7,%d iret;%d",emPlayState,iRet); if(emPlayState == TTS_PLAY_STATUS_FINISH) break; } } PLATFORM_DEBUG("over"); return ; }
最新发布
08-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值