国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【UE5/UE4】超詳細教程接入科大訊飛語音喚醒SDK并初始持久監(jiān)聽(10102錯誤碼解決)

這篇具有很好參考價值的文章主要介紹了【UE5/UE4】超詳細教程接入科大訊飛語音喚醒SDK并初始持久監(jiān)聽(10102錯誤碼解決)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

【UE5/UE4】超詳細教程接入科大訊飛語音喚醒SDK并初始持久監(jiān)聽(10102錯誤碼解決)

先導

Windows環(huán)境下
**UE版本為UE4.27及以下
你需要具備一定的C++基礎,或全程一對一對照我的代碼編寫你的代碼
使用Offline Voice Recognition插件作為錄音插件(僅做錄音插件使用)
基于https://github.com/zhangmei126/XunFei二次開發(fā)
語音識別部分參考CSDNUE4如何接入科大訊飛的語音識別
在此基礎上增加了語音喚醒功能,實際上語音喚醒與上述文章中是兩個模塊
由于訊飛插件的使用需要調用MSPLogin,也就是需要先注冊
科大訊飛invalid time or time required,ue5,ue4
其插件中的SpeechInit()方法已經(jīng)為我們注冊好了,如果可以自己寫注冊的話,后述本文語音喚醒部分是不分引擎版本的

語音喚醒環(huán)境配置

參考UE4如何接入科大訊飛的語音識別接入科大訊飛sdk以及使用Offline Voice Recognition插件了后,在plugins中確保他們都是開啟的狀態(tài)
科大訊飛invalid time or time required,ue5,ue4
科大訊飛invalid time or time required,ue5,ue4
你要確保你的SDK下載的是Windows版本以及一下SDK文件包
科大訊飛invalid time or time required,ue5,ue4
你要確保你的SDK下載后正確導入了且appid已經(jīng)擁有了正確的配置
科大訊飛invalid time or time required,ue5,ue4
你要確保你SDK下載后將Windows_awaken_exp1227_iat1226_af12f15d\bin\msc\res\ivw\wakeupresource.jet放置到了你的c盤根目錄下
科大訊飛invalid time or time required,ue5,ue4
to科大訊飛invalid time or time required,ue5,ue4
如果你是為了10102錯誤碼來此文章:
此處是訊飛的坑,訊飛的wakeupresource.jet的路徑必須是絕對路徑
c++中也就必須要使用轉義符"\\"即
const char* params = "ivw_threshold=0:5, ivw_res_path =fo|c:\\wakeupresource.jet";
至此10102解決了,就這么簡單,但是很坑
打開VisualStudio

  1. 打開訊飛插件文件夾
    科大訊飛invalid time or time required,ue5,ue4
  2. 在SpeechActor.cpp中引入qivw.h
    科大訊飛invalid time or time required,ue5,ue4
    qivw.h語音喚醒具備以下方法
    科大訊飛invalid time or time required,ue5,ue4
  3. 在SpeechActor.h中
#pragma once

#include "SpeechTask.h"

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "SpeechActor.generated.h"

UCLASS()
class XUNFEI_API ASpeechActor : public AActor
{
	GENERATED_BODY()
private:
	FString Result;
	DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWakeUpBufferDelegate);
public:
	// Sets default values for this actor's properties
	ASpeechActor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:
	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "SpeechInit", Keywords = "Speech Recognition Initialization"))
	void SpeechInit();

	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "SpeechOpen", Keywords = "Speech Recognition Open"))
	void SpeechOpen();

	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "SpeechStop", Keywords = "Speech Recognition Stop"))
	void SpeechStop();

	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "SpeechQuit", Keywords = "Speech Recognition Quit"))
	void SpeechQuit();
	
	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "SpeechResult", Keywords = "Speech Recognition GetResult"))
	FString SpeechResult();
	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "WakeUpStart", Keywords = "Speech Recognition GetResult"))
	FString WakeUpStart();
	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "WakeUpEnd", Keywords = "Speech Recognition GetResult"))
	bool WakeUpEnd(FString SessionID);
	UFUNCTION(BlueprintCallable, Category = "XunFei", meta = (DisplayName = "WakeUpBuffer", Keywords = "Speech Recognition GetResult"))
	bool WakeUpBuffer(TArray<uint8> MyArray, FString SessionID);

	//這是一個回調函數(shù)
	UPROPERTY(BlueprintAssignable)
	 FWakeUpBufferDelegate OnWakeUpBuffer;
	
};
  1. 在SpeechActor.cpp中
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once

#include "SpeechActor.h"
#include "XunFei.h"
#include "Dom/JsonObject.h"
#include "Serialization/JsonReader.h"
#include "Serialization/JsonSerializer.h"
#include <qivw.h>

// Sets default values
ASpeechActor::ASpeechActor() :
	Result{}
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;
}



// Called when the game starts or when spawned
void ASpeechActor::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void ASpeechActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void ASpeechActor::SpeechInit()
{
	FAutoDeleteAsyncTask<FSpeechTask>* SpeechTask = new FAutoDeleteAsyncTask<FSpeechTask>();

	if (SpeechTask)
	{
		SpeechTask->StartBackgroundTask();
	}
	else
	{
		UE_LOG(XunFeiLog, Error, TEXT("XunFei task object could not be create !"));
		return;
	}

	UE_LOG(XunFeiLog, Log, TEXT("XunFei Task Stopped !"));
	return;
}

void ASpeechActor::SpeechOpen()
{
	xunfeispeech->SetStart();
	return;
}

void ASpeechActor::SpeechStop()
{
	xunfeispeech->SetStop();
	return;
}

void ASpeechActor::SpeechQuit()
{
	xunfeispeech->SetQuit();
	Sleep(300);
	return;
}

FString ASpeechActor::SpeechResult()
{	
	Result = FString(UTF8_TO_TCHAR(xunfeispeech->get_result()));

	FString LajiString("{\"sn\":2,\"ls\":true,\"bg\":0,\"ed\":0,\"ws\":[{\"bg\":0,\"cw\":[{\"sc\":0.00,\"w\":\"\"}]}]}");

	int32 LajiIndex = Result.Find(*LajiString);

	if (LajiIndex != -1)
	{
		Result.RemoveFromEnd(LajiString);
	}

	TSharedPtr<FJsonObject> JsonObject;

	TSharedRef< TJsonReader<TCHAR> > Reader = TJsonReaderFactory<TCHAR>::Create(Result);

	if (FJsonSerializer::Deserialize(Reader, JsonObject))
	{
		Result.Reset();
		TArray< TSharedPtr<FJsonValue> > TempArray = JsonObject->GetArrayField("ws");
		for (auto rs : TempArray)
		{
			Result.Append((rs->AsObject()->GetArrayField("cw"))[0]->AsObject()->GetStringField("w"));
		}
	}

	UE_LOG(XunFeiLog, Log, TEXT("%s"), *Result);
	
	return Result;
}

// 在 cb_ivw_msg_proc 靜態(tài)函數(shù)中進行事件觸發(fā)
int cb_ivw_msg_proc(const char* sessionID1, int msg, int param1, int param2, const void* info, void* userData)
{
	if (MSP_IVW_MSG_ERROR == msg) //喚醒出錯消息
	{
		UE_LOG(LogTemp, Warning, TEXT("不在"));
		return 0;
	}
	else if (MSP_IVW_MSG_WAKEUP == msg) //喚醒成功消息
	{
		UE_LOG(LogTemp, Warning, TEXT("imhere"));
		if (userData) {
			ASpeechActor* MYThis = reinterpret_cast<ASpeechActor*>(userData);
			if (MYThis) {
				UE_LOG(LogTemp, Warning, TEXT("diaoyongle"));
				MYThis->OnWakeUpBuffer.Broadcast();
				return 1;
			}
		}
	}
	return 0;
}
FString ASpeechActor::WakeUpStart()
{
	int err_code = MSP_SUCCESS;
	const char* params = "ivw_threshold=0:5, ivw_res_path =fo|c:\\wakeupresource.jet";
	int ret = 0;
	const char* sessionID = QIVWSessionBegin(NULL, params, &ret);
	err_code = QIVWRegisterNotify(sessionID,cb_ivw_msg_proc, this);
	if (err_code != MSP_SUCCESS)
	{
		UE_LOG(LogTemp, Warning, TEXT("QIVWRegisterNotify failed, error code is: %d"), ret);
	}
	else {
		UE_LOG(LogTemp, Warning, TEXT("QIVWRegisterNotify success, error code is: %d"), ret);
	}
	
	if (MSP_SUCCESS != ret)
	{
		
		
		UE_LOG(LogTemp, Warning, TEXT("QIVWSessionBegin failed, error code is: %d"),ret);
	}
	return FString(sessionID);
	UE_LOG(LogTemp, Warning, TEXT("QIVWSessionBegin is working"));
	
	
}

bool ASpeechActor::WakeUpEnd(FString SessionID)
{
	
		int ret = QIVWSessionEnd(TCHAR_TO_ANSI(*SessionID) , "normal end");
	if (MSP_SUCCESS != ret)
	{
		UE_LOG(LogTemp, Warning, TEXT("QIVWSessionEnd failed, error code is: %d"), ret);
		return false;
	}
	UE_LOG(LogTemp, Warning, TEXT("QIVWSessioniSEnd"));
	return true;
}


bool ASpeechActor::WakeUpBuffer(TArray<uint8> BitArray, FString SessionID)
{
	int ret = 0;

	if (BitArray.Num() == 0)
	{
		
		return false;
	}
	else
	{
		int audio_len = BitArray.Num();
		int audio_status =2;  // 設置音頻狀態(tài),這里假設為MSP_AUDIO_SAMPLE_LAST

		ret = QIVWAudioWrite(TCHAR_TO_ANSI(*SessionID), BitArray.GetData(), audio_len, audio_status);
		if (MSP_SUCCESS != ret)
		{
				printf("QIVWAudioWrite failed, error code is: %d", ret);
				return false;
		}
		return true;
	}
}

至此準備工作完成
打開我們的藍圖

  1. 在確保你的Offline Voice Recognition插件打開的前提下添加vosk插件
    科大訊飛invalid time or time required,ue5,ue4

  2. 考慮本文的應用環(huán)境需要他初始化時就持續(xù)監(jiān)聽
    故而讓其開始運行時就開啟錄音(語音喚醒需要錄音文件才能監(jiān)聽)

科大訊飛invalid time or time required,ue5,ue4

  1. 接下里我們需要注冊訊飛,并且在運行結束釋放訊飛注冊
    科大訊飛invalid time or time required,ue5,ue4
    4.訊飛注冊后等待兩秒注冊我們的wakeup語音喚醒
    科大訊飛invalid time or time required,ue5,ue4
  2. 綁定一個喚醒事件

科大訊飛invalid time or time required,ue5,ue4
3. 在設置一個1.1秒的定時器
科大訊飛invalid time or time required,ue5,ue4
4. 定時器內部(正在語音識別默認值為false)
科大訊飛invalid time or time required,ue5,ue4
科大訊飛invalid time or time required,ue5,ue4
科大訊飛invalid time or time required,ue5,ue4
5. 語音喚醒的自定義事件(喚醒五秒鐘后恢復繼續(xù)監(jiān)聽)
科大訊飛invalid time or time required,ue5,ue4
藍圖文件以綁定
author:Dacimal
定制化開發(fā)聯(lián)系:19815779273(不閑聊)文章來源地址http://www.zghlxwxcb.cn/news/detail-845666.html

到了這里,關于【UE5/UE4】超詳細教程接入科大訊飛語音喚醒SDK并初始持久監(jiān)聽(10102錯誤碼解決)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 【UE5】離線AI聊天-接入LLAMA語言模型 教程

    【UE5】離線AI聊天-接入LLAMA語言模型 教程

    前言:LLAMA是一種神經(jīng)網(wǎng)絡模型,全稱為Language Model with an Average Attention Mechanism(具有平均注意機制的語言模型)。它是一種用于自然語言處理任務的模型,特別適用于生成文本和回答問題。LLAMA模型結合了注意力機制和平均池化,以提高模型對輸入文本的理解和生成能力。它

    2024年03月21日
    瀏覽(30)
  • vue使用科大訊飛的語音識別(語音聽寫)

    vue使用科大訊飛的語音識別(語音聽寫)

    使用的是封裝好的插件:voice-input-button2 真的很好使很好使 1、先使用npm下載插件 npm i voice-input-button2 -save -dev 2、在main.js中引入 import voiceInputButton from \\\'voice-input-button2\\\' Vue.use(voiceInputButton, { appId: \\\'xxx\\\', // 您申請的語音聽寫服務應用的ID apiKey: \\\'xxxxxxxxxxxxxxxxxxxxxxxxx\\\', // 您開通的語音

    2024年01月19日
    瀏覽(27)
  • 科大訊飛語音離線命令識別

    科大訊飛語音離線命令識別

    準備工作 注冊訊飛賬號,做相關的認證,只有認證通過才能下載部分免費的資源。官網(wǎng)地址:https://console.xfyun.cn/ 創(chuàng)建我的應用后再在離線命令識別 操作前先查看一下這個官方文檔Android 語音識別(Recognizer) | 訊飛開放平臺文檔中心 (xfyun.cn) 1、必要文件包復制到自己的項目目錄

    2023年04月08日
    瀏覽(25)
  • 科大訊飛語音SDK下載及測試

    科大訊飛語音SDK下載及測試

    一、SDK 下載 進入訊飛開發(fā)平臺官網(wǎng)http://www.xfyun.cn/,右上角進行注冊登錄,登錄后點擊進入SDK下載。 ?? ????????2.創(chuàng)建新應用 ????? ????????3.填入相關信息 ????????4.創(chuàng)建完后提交后回到SDK下載頁面,刷新頁面,應用選擇前面創(chuàng)建的應用,平臺選擇Linux,SDK選擇

    2024年02月08日
    瀏覽(42)
  • 科大訊飛語音合成Java springboot集成

    科大訊飛語音合成 文本轉語音 一、引入依賴: 二、下載響應的sdk,我這里是下載的java win版本的sdk SDK下載 - 科大訊飛api接口 - 訊飛開放平臺 三、具體代碼: 從下載的依賴里面找到對應文件,給代碼里面替換成你的絕對路徑,運行即可 備注:這個地方需要你自己的賬號下載

    2024年02月15日
    瀏覽(18)
  • vue 利用科大訊飛實現(xiàn)實時語音轉寫

    1:新建js文件,該文件在科大訊飛api的demo種可以找到 2: 引入第一個文件在vue頁面中 3:如果在引入的過程中有些關于worker的報錯,可以參考以下方法? 在vue.config.js中加入 ?

    2024年02月12日
    瀏覽(21)
  • 技術解讀 | 科大訊飛語音技術最新進展之二:語音識別與語音合成

    技術解讀 | 科大訊飛語音技術最新進展之二:語音識別與語音合成

    這一篇內容將圍繞語音識別與合成方向,繼續(xù)為大家?guī)硐嚓P技術解析。 “風物長宜放眼量”。面向人機交互更加自然流暢的未來,智能語音技術進展如何?該走向何方? 以下內容根據(jù)訊飛研究院杰出科學家潘嘉在NCMMSC 2022上的主題演講《科大訊飛語音技術前沿進展》整理。

    2024年02月07日
    瀏覽(74)
  • GEC6818科大訊飛離線語音識別

    GEC6818科大訊飛離線語音識別

    在下載SDK時需要注意選擇Linux的版本?。?在官網(wǎng)下載離線語音的包,解壓后可以得到下面的一些文件夾: 解壓后你需要知道自己命令放在下面的文件夾中 關于Make file文件: 關于asr_offline_sample.c文件: asr_offline_sample.c 文件是我們更改為自己的邏輯的文件,但是也不需要都了解

    2024年01月17日
    瀏覽(25)
  • C#調用科大訊飛離線語音合成實現(xiàn)文本轉語音

    C#調用科大訊飛離線語音合成實現(xiàn)文本轉語音

    文本轉語音(Text To Speech),簡稱TTS,在很多業(yè)務場景會用到,比如廣播大廳,人機互動等。C#要實現(xiàn)TTS有不少選擇,比如調用System.Speech,此處就不細說了,下面主要介紹一下C#調用科大訊飛的離線語音合成SDK來實現(xiàn)文本轉語音。 地址:[https://www.xfyun.cn/service/offline_tts] 一、創(chuàng)建

    2024年02月12日
    瀏覽(18)
  • 微信小程序調用科大訊飛 在線合成語音接口(文字轉語音)

    科大訊飛在線文檔 https://www.xfyun.cn/doc/tts/online_tts/API.html 科大訊飛調用接口 地址 https://blog.csdn.net/jinxi1112/article/details/122835386 微信小程序base64轉ArrayBuffer替代方案 https://www.homedt.net/43939.html 注意點 調用函數(shù) 參考大佬的實例 這里說一下注意的點 微信小程序 不支持在線的 base64

    2024年02月10日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包