Unity access SDK-02 Baidu speech recognition 2 (Android version)

1. Development environment

System environment: Mac
development software: Unity 2019.2.8, Android Studio 4.0.1.
Required class library: the classes.jar package required by UnityPlayer, etc. Location in Mac: Find the PlaybackEngines folder in the same level directory of unity app in the application, AndroidPlayer/Variations/mono/Development/Classes/classes.jar

 

Two, Android Studio project construction

1. Open AndroidStudio and create a new project

2. Select "Empty Activity" 

3. Fill in the project configuration

3. Create a new AndroidLibrary module

4. Delete the app module

5. Copy the classes.jar package in Unity to the newly created AndroidLibrary module above, in the Libs directory

Mac computer, classes.jar file path: AndroidPlayer/Variations/mono/Development/Classes/classes.jar

Wid computer, classes.jar file path: Data->PlaybackEngines->androidplayer->Variations->mono->release->classes->classes.jar

6.File->Project Structure..->Modules->Dependencies Add classes.ja after selecting the just created Library in Modules

7. Create a new class under this Library, this class is in the src/main/java/... folder, the code is as follows:

package com.test.baiduspeech;
import android.app.Fragment;
import com.unity3d.player.UnityPlayer;

public class BaiduVoice extends Fragment {

    public static BaiduVoice instance;

    public static void start() {
        instance = new BaiduVoice();
        UnityPlayer.currentActivity.getFragmentManager().beginTransaction().add(instance, "BaiduVoice").commit();
    }

    public void Test(String msg)
    {
        //注意"BaiduSpeech"是Unity中挂载接收这条消息的GameObject对象名称
        UnityPlayer.UnitySendMessage("BaiduSpeech", "AndroidMsg", msg);
    }
}

 8. Select the Library ->Build->Make Modele just created "Your Library Name" to produce the .aar package. (After successful generation, an .aar file will be generated in the "your Library->build->outputs->aar" directory)

9. After getting the aar package, change its suffix to the compressed format (zip or rar), open the compressed package and delete the classes.jar under libs/ (the reason is that Unity will copy classes.jar in the installation directory again when packaging. To cause conflicts in the project,)

 

Unity source code: https://github.com/yongliangchen/BaiduSpeechForUnity.git

Android source code: https://github.com/yongliangchen/BaiduSpeechForAndroid.git

QQ exchange group: 94761835

Guess you like

Origin blog.csdn.net/a451319296/article/details/107547208