Skip to content

Commit 38af594

Browse files
committed
普通模式不再支持风格调整
1 parent c3dabd7 commit 38af594

13 files changed

+58
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
2022/08/16
1+
2022/07/17
2+
3+
普通模式音频格式只支持前面三个
4+
5+
添加预览语音
6+
7+
28

3-
普通模式不再支持风格调整

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<!-- 请求忽略电池优化 -->
1616
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
1717
<uses-permission android:name="android.permission.WAKE_LOCK" />
18-
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
18+
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />-->
1919
<uses-permission
2020
android:name="android.permission.DEVICE_POWER"
2121
tools:ignore="ProtectedPermissions" />
@@ -88,9 +88,9 @@
8888
</intent-filter>
8989
</activity>
9090

91+
<!-- android:directBootAware="true"-->
9192
<service
9293
android:name=".services.TTSService"
93-
android:directBootAware="true"
9494
android:exported="true"
9595
android:label="@string/app_name"
9696
tools:ignore="ExportedService,UnusedAttribute">

app/src/main/java/me/ag2s/tts/services/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final class Constants {
5757

5858

5959
public static final String EDGE_ORIGIN = "chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold";
60-
public static final String EDGE_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.124 Safari/537.36 Edg/102.0.1245.41";
60+
public static final String EDGE_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.62";
6161
public static final String EDGE_URL = "https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=6A5AA1D4EAFF4E9FB37E23D68491D6F4";
6262

6363
}

app/src/main/java/me/ag2s/tts/services/TTSService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class TTSService extends TextToSpeechService {
6060

6161
private PowerManager.WakeLock mWakeLock;
6262

63+
private volatile WebSocketState webSocketState = WebSocketState.OFFLINE;
64+
6365

6466
private static final String TAG = TTSService.class.getSimpleName();
6567

@@ -100,7 +102,9 @@ public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String rea
100102
public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
101103
super.onClosing(webSocket, code, reason);
102104
Log.e(TAG, "onClosing:" + reason);
105+
103106
TTSService.this.webSocket = null;
107+
webSocketState = WebSocketState.OFFLINE;
104108

105109
Log.e("SS", "SS:" + isSynthesizing);
106110
if (isSynthesizing) {
@@ -115,13 +119,14 @@ public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String re
115119
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, @Nullable Response response) {
116120
super.onFailure(webSocket, t, response);
117121
TTSService.this.webSocket = null;
122+
webSocketState = WebSocketState.OFFLINE;
118123
Log.e(TAG, "onFailure" + t.getMessage(), t);
119124
if (isSynthesizing) {
120125
TTSService.this.webSocket = getOrCreateWs();
121126
}
122127
updateNotification("TTS服务-错误中", t.getMessage());
123128

124-
//APP.showToast("网络发生波动,掉线了,正在重连。");
129+
APP.showToast("发生错误:" + t.getMessage());
125130

126131

127132
}
@@ -565,6 +570,7 @@ public WebSocket getOrCreateWs() {
565570
synchronized (TTSService.class) {
566571
if (this.webSocket == null) {
567572

573+
568574
while (TokenHolder.token == null) {
569575
try {
570576
this.wait(500);
@@ -573,6 +579,15 @@ public WebSocket getOrCreateWs() {
573579
}
574580
}
575581

582+
//避免同时重复请求
583+
while (webSocketState == WebSocketState.CONNECTING) {
584+
try {
585+
this.wait(500);
586+
} catch (InterruptedException e) {
587+
e.printStackTrace();
588+
}
589+
}
590+
576591
String url;
577592
String origin;
578593
if (TokenHolder.token != null && APP.getBoolean(Constants.USE_PREVIEW, false)) {
@@ -591,7 +606,9 @@ public WebSocket getOrCreateWs() {
591606
.header("User-Agent", Constants.EDGE_UA)
592607
.addHeader("Origin", origin)
593608
.build();
609+
webSocketState = WebSocketState.CONNECTING;
594610
this.webSocket = client.newWebSocket(request, webSocketListener);
611+
webSocketState = WebSocketState.CONNECTED;
595612
sendConfig(Objects.requireNonNull(this.webSocket), new TtsConfig.Builder(APP.getInt(Constants.AUDIO_FORMAT_INDEX, 0)).build());
596613

597614
}

app/src/main/java/me/ag2s/tts/services/TtsActorManger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ private TtsActorManger() {
6969
actors.add(new TtsActor("云枫", "zh-CN-YunfengNeural", "zh-CN", false, "" + previewNote));
7070
actors.add(new TtsActor("云皓", "zh-CN-YunhaoNeural", "zh-CN", false, "" + previewNote));
7171
actors.add(new TtsActor("云健", "zh-CN-YunjianNeural", "zh-CN", false, "适合影视和体育解说," + previewNote));
72+
actors.add(new TtsActor("云泽", "zh-CN-YunzeNeural", "zh-CN", false, "老年男声," + previewNote));
73+
actors.add(new TtsActor("云夏", "zh-CN-YunxiaNeural", "zh-CN", false, "少年年男声," + previewNote));
7274

7375

7476
actors.add(new TtsActor("晓涵", "zh-CN-XiaohanNeural", "zh-CN", true, "温暖、甜美、富有感情的声音,可用于许多对话场景。"));

app/src/main/java/me/ag2s/tts/services/TtsFormatManger.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public static TtsFormatManger getInstance() {
2626

2727
public TtsFormatManger() {
2828
formats = new ArrayList<>();
29+
this.formats.add(new TtsOutputFormat(TtsOutputFormat.TAG + "audio-24khz-48kbitrate-mono-mp3", 24000, AudioFormat.ENCODING_PCM_16BIT, true));
30+
this.formats.add(new TtsOutputFormat(TtsOutputFormat.TAG + "audio-24khz-96kbitrate-mono-mp3", 24000, AudioFormat.ENCODING_PCM_16BIT, true));
31+
this.formats.add(new TtsOutputFormat(TtsOutputFormat.TAG + "webm-24khz-16bit-mono-opus", 24000 * 2, AudioFormat.ENCODING_PCM_16BIT, true));
32+
2933
this.formats.add(new TtsOutputFormat("raw-16khz-16bit-mono-pcm", 16000, AudioFormat.ENCODING_PCM_16BIT));
3034
this.formats.add(new TtsOutputFormat("raw-24khz-16bit-mono-pcm", 24000, AudioFormat.ENCODING_PCM_16BIT));
3135
this.formats.add(new TtsOutputFormat("raw-48khz-16bit-mono-pcm", 48000, AudioFormat.ENCODING_PCM_16BIT));
@@ -45,8 +49,6 @@ public TtsFormatManger() {
4549
this.formats.add(new TtsOutputFormat("audio-16khz-128kbitrate-mono-mp3", 16000, AudioFormat.ENCODING_PCM_16BIT, true));
4650

4751

48-
this.formats.add(new TtsOutputFormat("audio-24khz-48kbitrate-mono-mp3", 24000, AudioFormat.ENCODING_PCM_16BIT, true));
49-
this.formats.add(new TtsOutputFormat("audio-24khz-96kbitrate-mono-mp3", 24000, AudioFormat.ENCODING_PCM_16BIT, true));
5052
this.formats.add(new TtsOutputFormat("audio-24khz-160kbitrate-mono-mp3", 24000, AudioFormat.ENCODING_PCM_16BIT, true));
5153

5254
this.formats.add(new TtsOutputFormat("audio-48khz-96kbitrate-mono-mp3", 48000, AudioFormat.ENCODING_PCM_16BIT, true));
@@ -61,13 +63,13 @@ public TtsFormatManger() {
6163
this.formats.add(new TtsOutputFormat("riff-24khz-16bit-mono-pcm", 24000, AudioFormat.ENCODING_PCM_16BIT));
6264
this.formats.add(new TtsOutputFormat("riff-48khz-16bit-mono-pcm", 48000, AudioFormat.ENCODING_PCM_16BIT));
6365

64-
//下面的几个不能正确的被MediaCodec解码
66+
6567
this.formats.add(new TtsOutputFormat("ogg-16khz-16bit-mono-opus", 16000 * 3, AudioFormat.ENCODING_PCM_16BIT, true));
6668
this.formats.add(new TtsOutputFormat("ogg-24khz-16bit-mono-opus", 24000 * 2, AudioFormat.ENCODING_PCM_16BIT, true));
6769
this.formats.add(new TtsOutputFormat("ogg-48khz-16bit-mono-opus", 48000, AudioFormat.ENCODING_PCM_16BIT, true));
6870

6971
this.formats.add(new TtsOutputFormat("webm-16khz-16bit-mono-opus", 16000 * 3, AudioFormat.ENCODING_PCM_16BIT, true));
70-
this.formats.add(new TtsOutputFormat("webm-24khz-16bit-mono-opus", 24000 * 2, AudioFormat.ENCODING_PCM_16BIT, true));
72+
7173
//this.formats.add(new TtsOutputFormat("webm-48khz-16bit-mono-opus",48000,AudioFormat.ENCODING_PCM_16BIT,true));
7274

7375

app/src/main/java/me/ag2s/tts/services/TtsOutputFormat.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.jetbrains.annotations.NotNull;
66

77
public class TtsOutputFormat {
8+
public static final String TAG = "\uD83D\uDC96";
89
@NonNull
910
public final String name;
1011
@NonNull
@@ -25,7 +26,13 @@ public TtsOutputFormat(@NonNull String name, int hz, int bitRate) {
2526

2627
public TtsOutputFormat(@NonNull String name, int hz, int bitRate, boolean needDecode) {
2728
this.name = name;
28-
this.value = name;
29+
if (name.contains(TAG)) {
30+
this.value = name.substring(TAG.length());
31+
} else {
32+
this.value = name;
33+
}
34+
35+
2936
this.HZ = hz;
3037
this.BitRate = (byte) bitRate;
3138
this.needDecode = needDecode;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package me.ag2s.tts.services;
2+
3+
public enum WebSocketState {
4+
OFFLINE,//断线
5+
CONNECTED,//已连接
6+
CONNECTING //连接中
7+
}

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
buildscript {
33
ext{
44
agp_version= '7.2.1'
5-
kotlin_version = '1.7.0'
6-
okhttp_version= '5.0.0-alpha.9'
7-
okio_version="3.1.0"
5+
kotlin_version = '1.7.10'
6+
okhttp_version= '5.0.0-alpha.10'
7+
okio_version="3.2.0"
88
}
99
}
1010
plugins {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Apr 06 22:19:25 CST 2022
1+
#Sun Jul 17 20:47:45 CST 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)