• 大小: 59.46MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-19
  • 语言: Java
  • 标签: Unity  XunFei  Android  Speak  

资源简介

Unity 接入讯飞语音识别包,实现语音识别,包含Unity 项目工程和Android安装包

资源截图

代码片段和文件信息

package com.ssm.ssm.speechrecognizer;

        import android.os.Bundle;
        import android.util.Log;
        import android.widget.Toast;

        import com.iflytek.cloud.InitListener;
        import com.iflytek.cloud.RecognizerListener;
        import com.iflytek.cloud.RecognizerResult;
        import com.iflytek.cloud.SpeechConstant;
        import com.iflytek.cloud.SpeechError;
        import com.iflytek.cloud.SpeechSynthesizer;
        import com.iflytek.cloud.SpeechUtility;
        import com.iflytek.cloud.SpeechRecognizer;

        import com.iflytek.cloud.SynthesizerListener;
        import com.unity3d.player.UnityPlayer;
        import com.unity3d.player.UnityPlayerActivity;

        import org.json.JSONArray;
        import org.json.JSONobject;
        import org.json.JSONTokener;

public class MainActivity extends UnityPlayerActivity {

    public SpeechRecognizer speechRecognizer;
    public SpeechSynthesizer speechSynthesizer;
    private String ttsSpeakerName = “yefang“;
    private String ttsSpeakerPitch = “50“;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //注意这里的appid为
        SpeechUtility.createUtility(getApplicationContext()“appid=58880d30“);

        initRecognizer();
    }

    //初始化
    private void initRecognizer(){
        speechRecognizer = SpeechRecognizer.createRecognizer(getApplicationContext()mInitListener);

        speechSynthesizer = SpeechSynthesizer.createSynthesizer(getApplicationContext()mInitListener);
    }

    public InitListener mInitListener = new InitListener() {
        @Override
        public void onInit(int i) {
            UnityPlayer.UnitySendMessage(“Manager“ “Result“ “init success!“);
        }
    };

    public void setTTSSpeaker(String targetName) {
        ttsSpeakerName = targetName;
    }

    public void setTTSPitch(String targetPitch) {
        ttsSpeakerPitch = targetPitch;
    }

    public void doTTS(String ttsStr){
        UnityPlayer.UnitySendMessage(“MotionManager“ “IsSpeaking“ “true“);

        //设置发音人
        speechSynthesizer.setParameter(SpeechConstant.VOICE_NAMEttsSpeakerName);
        //设置音调
        speechSynthesizer.setParameter(SpeechConstant.PITCHttsSpeakerPitch);
        //设置音量
        speechSynthesizer.setParameter(SpeechConstant.VOLUME“50“);
        int code = speechSynthesizer.startSpeaking(ttsStr mTTSListener);
    }

    private SynthesizerListener mTTSListener = new SynthesizerListener() {
        @Override
        public void onSpeakBegin() {

        }

        @Override
        public void onBufferProgress(int i int i1 int i2 String s) {

        }

        @Override
        public void onSpeakPaused() {

        }

        @Override
        public void onSpeakResumed() {

        }

        @Override
        public void onSpeakProgress(int i int i1 int i2) {

        }

        @Override
        public void onCompleted(SpeechError speechError) {
            UnityP

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\
     文件       11343  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\README.md
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\
     文件         118  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.gitignore
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\
     文件         686  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\compiler.xml
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\copyright\
     文件          74  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\copyright\profiles_settings.xml
     文件         640  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\gradle.xml
     文件        2226  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\misc.xml
     文件         425  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\modules.xml
     文件         564  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\.idea\runConfigurations.xml
     文件         498  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\build.gradle
     文件         730  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\gradle.properties
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\gradle\
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\gradle\wrapper\
     文件       53636  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\gradle\wrapper\gradle-wrapper.jar
     文件         233  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\gradle\wrapper\gradle-wrapper.properties
     文件        4971  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\gradlew
     文件        2314  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\gradlew.bat
     文件          29  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\settings.gradle
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\
     文件           7  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\.gitignore
     文件        1305  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\build.gradle
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\libs\
     文件      429493  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\libs\Msc.jar
     文件       63418  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\libs\classes.jar
     文件         671  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\proguard-rules.pro
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\src\
     目录           0  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\src\main\
     文件        2064  2017-02-18 05:56  Unity_XunFeiAndroidSDK-master\SpeechRecognizer\speechrecognizer2\src\main\AndroidManifest.xml
............此处省略2002个文件信息

评论

共有 条评论