fctom1215
2020-03-10 4d625b8f7d4eb22209dba53cf19353d8aa7455ea
修改TTS播放。
4个文件已修改
1个文件已添加
78 ■■■■ 已修改文件
lib/src/main/cpp/driver_test.cpp 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/cpp/master/comm_if.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/java/com/anyun/exam/lib/RemoteService.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/java/com/anyun/exam/lib/util/Speaker.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/java/com/anyun/exam/lib/util/SpeakerCallback.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/src/main/cpp/driver_test.cpp
@@ -374,6 +374,8 @@
void SetDummyLightExam(int n, struct dummy_light_exam *cfg)
{
    DEBUG("获取模拟路考灯光测试项目");
    if (TestStart) return;
    if (DummyLightContent != NULL) {
@@ -392,18 +394,15 @@
void StartDriverExam(int start, int type)
{
    bool err = false;
    DEBUG("++++++++++++考试启动 start %d type %d+++++++++++++", start, type);
    if (start == 0) {
        DEBUG("-------------结束考试----------------");
//        CurrExamMapIndex = -1;
//        TestStart = false;
//        CommTestStart(false);
//        MA_SendExamStatus(0, 0);
        return;
    }
    DEBUG("+++++++++++++++开始考试++++++++++++++++++++");
    if (MapNum == 0) {
        err = true;
@@ -424,6 +423,7 @@
            examFaultIndex = 0;
            TestStart = true;
            TestType = type;
            CommTestStart(true);
            if (type == TEST_TYPE_ROAD_DUMMY_LIGHT) {
lib/src/main/cpp/master/comm_if.cpp
@@ -791,7 +791,7 @@
                                const Value &s2 = (*itr)["tts"];
                                content[n].item = s1.GetInt();
                                strcpy(content[n].tts, s1.GetString());
                                strcpy(content[n].tts, s2.GetString());
                                n++;
                            }
                        }
lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -13,6 +13,7 @@
import com.anyun.exam.lib.util.DESUtil;
import com.anyun.exam.lib.util.NetUtils;
import com.anyun.exam.lib.util.Speaker;
import com.anyun.exam.lib.util.SpeakerCallback;
import androidx.annotation.Nullable;
@@ -78,7 +79,7 @@
    public void onCreate() {
        super.onCreate();
        Log.i(TAG,"onCreate()");
        speaker = new Speaker(getApplicationContext());
        speaker = new Speaker(/*getApplicationContext()*/this, new TTSCallback());
        new Thread(new StartNative()).start();
@@ -93,7 +94,6 @@
            } catch (InterruptedException e) {
            }
            ttsInitSucc = true;
        }
    }
@@ -186,6 +186,29 @@
        return h.toString();
    }
    class TTSCallback implements SpeakerCallback {
        @Override
        public void PlayInit(boolean ret) {
            Log.d(TAG, "TTS引擎初始化成功");
            ttsInitSucc = ret;
        }
        @Override
        public void PlayStart() {
            Log.d(TAG, "TTS引擎播放开始");
        }
        @Override
        public void PlayDone() {
            Log.d(TAG, "TTS引擎播放结束");
        }
        @Override
        public void PlayError() {
            Log.d(TAG, "TTS引擎播放出错");
        }
    }
    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
lib/src/main/java/com/anyun/exam/lib/util/Speaker.java
@@ -2,6 +2,7 @@
import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.util.Log;
import com.anyun.exam.lib.RemoteService;
@@ -11,13 +12,16 @@
public class Speaker {
    private Context context;
    private TextToSpeech tts;
    private SpeakerCallback callback = null;
    final public String TAG = Speaker.class.getCanonicalName();
    public Speaker(final Context context) {
    public Speaker(final Context context, final SpeakerCallback cb) {
        // TODO Auto-generated constructor stub
        Log.d(TAG, "Speaker Init...");
        this.context = context;
        this.callback = cb;
        tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
@@ -34,13 +38,38 @@
                    {
                        Log.d(TAG, "TextToSpeech.LANG_NOT_SUPPORTED");
                    }
                    if (callback != null) {
                        callback.PlayInit(true);
                    }
                }
            }
        });
        tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
            @Override
            public void onStart(String s) {
                if (callback != null) {
                    callback.PlayStart();
                }
            }
            @Override
            public void onDone(String s) {
                if (callback != null) {
                    callback.PlayDone();
                }
            }
            @Override
            public void onError(String s) {
                if (callback != null) {
                    callback.PlayError();
                }
            }
        });
    }
    public void speak(String text) {
        Log.d(TAG, "SPEAK");
//            tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
        tts.speak(text, TextToSpeech.QUEUE_ADD, null, "speech");
    }
lib/src/main/java/com/anyun/exam/lib/util/SpeakerCallback.java
New file
@@ -0,0 +1,8 @@
package com.anyun.exam.lib.util;
public interface SpeakerCallback {
    void PlayInit(boolean ret);
    void PlayStart();
    void PlayDone();
    void PlayError();
}