bool FSpeechRecognitionWorker::Init() { std::string modelPath = contentPath_str + "model/" + langStr + "/" + langStr; std::string languageModel = contentPath_str + "model/" + langStr + "/" + langStr + ".lm.bin"; std::string dictionaryPath = contentPath_str + "model/" + langStr + "/" + langStr + ".dict"; // load dictionary dictionaryMap.clear(); std::ifstream file(dictionaryPath); std::vector<std::string> words; std::string currentLine; while (file.good()) { std::getline(file, currentLine); std::string word = currentLine.substr(0, currentLine.find(" ")); std::string phrase = currentLine.substr(currentLine.find(" ") + 1, currentLine.size()); dictionaryMap.insert(make_pair(word, phrase)); } // Start Sphinx config = cmd_ln_init(NULL, ps_args(), 1, "-hmm", modelPath.c_str(), "-lm", languageModel.c_str(), NULL); ps = ps_init(config); if (!Manager | !ps) { ClientMessage(FString(TEXT("Speech Recognition Thread failed to start"))); initSuccess = false; return false; } // only include the words/phrases that have been added for (auto It = dictionaryList.CreateConstIterator(); It; ++It) { FString word = *It; std::string wordStr = std::string(TCHAR_TO_UTF8(*word)); if (dictionaryMap.find(wordStr) != dictionaryMap.end()) { std::string phraseStr = dictionaryMap.at(wordStr); ps_add_word(ps, wordStr.c_str(), phraseStr.c_str(), TRUE); } } // attempt to open the default recording device if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int)cmd_ln_float32_r(config, "-samprate"))) == NULL) { ClientMessage(FString(TEXT("Failed to open audio device"))); initSuccess = false; return initSuccess; } utt_started = 0; return true; }
void NetworkManager::handle_receive(const boost::system::error_code& error, std::size_t bytes_transferred){ if (!error) { ClientMessage message = ClientMessage(std::string(recv_buffer.data(), recv_buffer.data() + bytes_transferred), get_client_id(remote_endpoint)); if (!message.first.empty()) { boost::mutex::scoped_lock lock(mutex); messages.push(message); if(timeLeft.find(message.second) != timeLeft.end()) timeLeft[message.second] = (int) clock(); else timeLeft[nextClientID + 1] = (int) clock(); cout << message.first <<"\n"; } else { cout << "empty message\n"; } receivedBytes += bytes_transferred; receivedMessages++; } else { cout << "error!" <<"\n"; } start_receive(); }
void AShooterPlayerController::ServerCheat_Implementation(const FString& Msg) { if (CheatManager) { ClientMessage(ConsoleCommand(Msg)); } }
uint32 FSpeechRecognitionWorker::Run() { char const *hyp; // attempt to open the default recording device if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int)cmd_ln_float32_r(config, "-samprate"))) == NULL) { ClientMessage(FString(TEXT("Failed to open audio device"))); return 1; } if (ad_start_rec(ad) < 0) { ClientMessage(FString(TEXT("Failed to start recording"))); return 2; } if (ps_start_utt(ps) < 0) { ClientMessage(FString(TEXT("Failed to start utterance"))); return 3; } while (StopTaskCounter.GetValue() == 0) { if ((k = ad_read(ad, adbuf, 1024)) < 0) ClientMessage(FString(TEXT("Failed to read audio"))); ps_process_raw(ps, adbuf, k, 0, 0); in_speech = ps_get_in_speech(ps); if (in_speech && !utt_started) { utt_started = 1; } if (!in_speech && utt_started) { /* speech -> silence transition, time to start new utterance */ ps_end_utt(ps); hyp = ps_get_hyp(ps, NULL); if (hyp != NULL) Manager->WordSpoken_method(FString(hyp)); if (ps_start_utt(ps) < 0) ClientMessage(FString(TEXT("Failed to start"))); utt_started = 0; } } ad_close(ad); return 0; }
int ClientHandlerNotice(PCLIENT pClient, char* strCommand, char* strParams) { if(CompareIRCAddressNick(strParams,c_strBouncerName)) { char *strAction,*str; pClient->cMessageMode = CMM_NOTICE; strAction = strParams+strlen(c_strBouncerName)+1; if(*strAction == ':') strAction++; str = strAction; do { if(*str == ' ') { *(str++) = '\0'; break; } else if(*str == '\r' || *str == '\n') { *str = '\0'; break; } *str = toupper(*str); ++str; } while(*str); { struct tagCLIENTHANDLER* pHandler; HASH_LOOKUP(CLIENTHANDLER_HASH,g_hashClientHandlers,strAction,pHandler); if(pHandler && ( !(pHandler->nFlags & CHF_BOUNCER) || (!(pHandler->nFlags & CHF_ADMIN) && (!pClient->pUser->strAllowedCommands || !ConfigFindVar(pClient->pUser->strAllowedCommands,pHandler->strAction))) || (pHandler->nFlags & CHF_ADMIN && !pClient->bAdmin) ) ) pHandler = 0; if(pHandler) { sprintf(strCommand,"notice %s %s",c_strBouncerName,pHandler->strAction); pHandler->pProc(pClient,strCommand,str); } else ClientMessage(pClient,"Unknown command \"%s\"\r\n",strAction); } pClient->cMessageMode = CMM_DEFAULT; return 1; } { char* strArg[2]; if(SplitIRCParams(strParams,strArg,sizeof(strArg)/sizeof(*strArg),1) == sizeof(strArg)/sizeof(*strArg)) { if(*strArg[1] == '\001' && strncmp(&strArg[1][1],"ACTION ",7) ) /* ctcp answer */ { if(!strncmp(&strArg[1][1],"VERSION",7) ) /* hook version answer */ { if(pClient->pProfile && pClient->pProfile->pServer && pClient->pProfile->pServer->bRegistered) { char* strCtcpArg = &strArg[1][8]; char* str; if(*strCtcpArg == ' ') strCtcpArg++; str = strCtcpArg+strlen(strCtcpArg)-1; if(*str == '\001') *str = '\0'; ConnectionSendFormat(pClient->pProfile->pServer->pConnection,"NOTICE %s :\001VERSION %s - %s\001\r\n",strArg[0],g_strVersion,strCtcpArg); } return 1; } return 0; /* don't log ctcp answers */ } if(pClient->pProfile) { PPROFILE pProfile = pClient->pProfile; PPROFILECHANNEL pProfileChannel; HASHLIST_LOOKUP(PROFILE_PROFILECHANNEL_HASHLIST,pProfile->hashlistProfileChannels,strArg[0],pProfileChannel); if(pProfileChannel) { PCLIENT pCurClient; ProfileLogMsgCreate(0,pProfileChannel,++pProfile->nLogID,g_strCurrentCommand,g_nCurrentCommandLength,PLMF_TIMESTAMP|PLMF_ADJUSTNICKLEN); for(pCurClient = pProfile->listClients.pFirst; pCurClient; pCurClient = pCurClient->llProfile.pNext) if(pCurClient != pClient) ConnectionSendFormat(pCurClient->pConnection,":%s!~%s@%s NOTICE %s :%s\r\n",pClient->strNick,pClient->pUser->strName,iptoa(pClient->pConnection->nIP),strArg[0],strArg[1]); } } } } return 0; }
int ClientHandlerPrivmsg(PCLIENT pClient, char* strCommand, char* strParams) { if(CompareIRCAddressNick(strParams,c_strBouncerName)) { char *strAction,*str; pClient->cMessageMode = CMM_PRIVMSG; strAction = strParams+strlen(c_strBouncerName)+1; if(*strAction == ':') strAction++; str = strAction; do { if(*str == ' ') { *(str++) = '\0'; break; } else if(*str == '\r' || *str == '\n') { *str = '\0'; break; } *str = toupper(*str); ++str; } while(*str); { struct tagCLIENTHANDLER* pHandler; HASH_LOOKUP(CLIENTHANDLER_HASH,g_hashClientHandlers,strAction,pHandler); if(pHandler && ( !(pHandler->nFlags & CHF_BOUNCER) || (!(pHandler->nFlags & CHF_ADMIN) && (!pClient->pUser->strAllowedCommands || !ConfigFindVar(pClient->pUser->strAllowedCommands,pHandler->strAction))) || (pHandler->nFlags & CHF_ADMIN && !pClient->bAdmin) ) ) pHandler = 0; if(pHandler) { sprintf(strCommand,"msg %s %s",c_strBouncerName,pHandler->strAction); pHandler->pProc(pClient,strCommand,str); } else ClientMessage(pClient,"Unknown command \"%s\"\r\n",strAction); } pClient->cMessageMode = CMM_DEFAULT; return 1; } { char* strArg[2]; if(SplitIRCParams(strParams,strArg,sizeof(strArg)/sizeof(*strArg),1) == sizeof(strArg)/sizeof(*strArg)) { if(pClient->pProfile) { PPROFILE pProfile = pClient->pProfile; PPROFILECHANNEL pProfileChannel; HASHLIST_LOOKUP(PROFILE_PROFILECHANNEL_HASHLIST,pProfile->hashlistProfileChannels,strArg[0],pProfileChannel); if(pProfileChannel) { PCLIENT pCurClient; unsigned short sLength; sLength = strformat(g_strOutBuffer,sizeof(g_strOutBuffer),":%s!~%s@%s PRIVMSG %s :%s\r\n",pClient->strNick,pClient->pUser->strName,iptoa(pClient->pConnection->nIP),strArg[0],strArg[1]); for(pCurClient = pProfile->listClients.pFirst; pCurClient; pCurClient = pCurClient->llProfile.pNext) if(pCurClient != pClient) ConnectionSend(pCurClient->pConnection,g_strOutBuffer,sLength); ProfileLogMsgCreate(0,pProfileChannel,++pProfile->nLogID,g_strOutBuffer,sLength,PLMF_TIMESTAMP|PLMF_ADJUSTNICKLEN); } } } } return 0; }