Androidstudio->jar->unity3d realization of voice-over-flight audio access

Source: Internet
Author: User

I. References

[MEMORYC] Unity3d calling Android features and components (eight)--speech recognition and synthesis of the message flight

Two. Successful export of Jar

The directory structure in 1.mylibrary

2. Export jar

Task Makejar (type:copy) {
Delete the existing
Delete ' Build/libs/mytest.jar '
Set up a copied file
From (' build/intermediates/packaged-classes/release/')
File directory after hitting the jar package
Into (' build/libs/')
Put the Classes.jar into the build/libs/directory
Include, exclude parameter to set filter
(We only care about Classes.jar this file)
Include (' Classes.jar ')
Renaming
Rename (' Classes.jar ', ' Mytest.jar ')
}
Makejar.dependson (build)

Note: This is the Gradle in MyLibrary.

3. Import the generated jar file into U3d, Test testu2a (), Success!

Three. Add and rewrite the Iflyvoicejava code

1. Import related libs

2. Copy the code in Ifyvoicejava.class to Mylibrary1.java and overwrite the related function

3. Re-Makejar and import the U3d

Four. Implement change of voice voicer

1. Discard VoiceStatic.cs, re-encapsulate T2VStatic.CS

usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classt2vstatic{ Public Static ReadOnlyt2vstatic instance = (t2vstatic) activator.createinstance (typeof(t2vstatic)); //AndroidjavaclassAndroidjavaclass JC;    Androidjavaobject Jo;    Androidjavaobject Jo1;  Publict2vstatic () {#ifUnity_android//Initialize Androidjavaclass (please don't delete the commended codes for that those code is for test and check)JC =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer"); Jo= JC. Getstatic<androidjavaobject> ("currentactivity"); Jo1=NewAndroidjavaobject ("Com.unity3d.player.mylibrary1","5b508fb6", Jo); //string str = Setvoicer (VoI);Jo1. Call ("Setinitlistener",NewXfinitlistener ()); Jo1. Call ("Setttslistener",NewXfsynthesizerlistener ()); //Jo1. Call (methodName: "Setrecognizerlistener", Args:new Xfrecognizerlistener ());Jo1. Call ("Initvoice"); //startrecognize (); //startspeaking ("Hello, imp,, haha haha!") Good morning! congratulations! Hoooray! ");#endif        }     Public voidStartspeaking (intVoI,stringtext) {Jo1. Call ("Setttsparam", Setvoicer (VoI)); Jo1. Call ("Startspeak",NewAndroidjavaobject ("java.lang.String", text)); }     Public voidstartrecognize () {jo1. Call ("startrecognize"); }    Private stringSetvoicer (inti) {stringstr =""; Switch(i) { Case 0: Str="XiaoYan";//Young female voice, Chinese and English                 Break;  Case 1: Str="Xiaoyu";//Young male speaker, Mandarin Chinese and English                 Break;  Case 2: Str="Catherine";//young girls,, English                 Break;  Case 3: Str="Henry";//young male,, English                 Break;  Case 4: Str="Xiaofeng";//young boys, Chinese and English                 Break;  Case 5: Str="xiaoxin";//childhood male, Mandarin Chinese                 Break;  Case 6: Str="Nannan";//female voice in the same year, Mandarin Chinese                 Break;  Case 7: Str="vils";//Senior male speaker, Mandarin Chinese                 Break; default: Str="XiaoYan";  Break; }        returnstr; }}

2. Call Example:

string " Welcome to XX Paradise! " ;        T2VStatic.instance.startSpeaking (6, str);

Finished, thank you!

Androidstudio->jar->unity3d realization of voice-over-flight audio access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.