Skip to content

Commit

Permalink
普通模式不再支持风格调整
Browse files Browse the repository at this point in the history
  • Loading branch information
ag2s20150909 committed Jul 17, 2022
1 parent c3dabd7 commit 38af594
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 18 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2022/08/16
2022/07/17

普通模式音频格式只支持前面三个

添加预览语音



普通模式不再支持风格调整
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- 请求忽略电池优化 -->
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />-->
<uses-permission
android:name="android.permission.DEVICE_POWER"
tools:ignore="ProtectedPermissions" />
Expand Down Expand Up @@ -88,9 +88,9 @@
</intent-filter>
</activity>

<!-- android:directBootAware="true"-->
<service
android:name=".services.TTSService"
android:directBootAware="true"
android:exported="true"
android:label="@string/app_name"
tools:ignore="ExportedService,UnusedAttribute">
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/me/ag2s/tts/services/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class Constants {


public static final String EDGE_ORIGIN = "chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold";
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";
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";
public static final String EDGE_URL = "https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=6A5AA1D4EAFF4E9FB37E23D68491D6F4";

}
19 changes: 18 additions & 1 deletion app/src/main/java/me/ag2s/tts/services/TTSService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class TTSService extends TextToSpeechService {

private PowerManager.WakeLock mWakeLock;

private volatile WebSocketState webSocketState = WebSocketState.OFFLINE;


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

Expand Down Expand Up @@ -100,7 +102,9 @@ public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String rea
public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
super.onClosing(webSocket, code, reason);
Log.e(TAG, "onClosing:" + reason);

TTSService.this.webSocket = null;
webSocketState = WebSocketState.OFFLINE;

Log.e("SS", "SS:" + isSynthesizing);
if (isSynthesizing) {
Expand All @@ -115,13 +119,14 @@ public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String re
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, @Nullable Response response) {
super.onFailure(webSocket, t, response);
TTSService.this.webSocket = null;
webSocketState = WebSocketState.OFFLINE;
Log.e(TAG, "onFailure" + t.getMessage(), t);
if (isSynthesizing) {
TTSService.this.webSocket = getOrCreateWs();
}
updateNotification("TTS服务-错误中", t.getMessage());

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


}
Expand Down Expand Up @@ -565,6 +570,7 @@ public WebSocket getOrCreateWs() {
synchronized (TTSService.class) {
if (this.webSocket == null) {


while (TokenHolder.token == null) {
try {
this.wait(500);
Expand All @@ -573,6 +579,15 @@ public WebSocket getOrCreateWs() {
}
}

//避免同时重复请求
while (webSocketState == WebSocketState.CONNECTING) {
try {
this.wait(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

String url;
String origin;
if (TokenHolder.token != null && APP.getBoolean(Constants.USE_PREVIEW, false)) {
Expand All @@ -591,7 +606,9 @@ public WebSocket getOrCreateWs() {
.header("User-Agent", Constants.EDGE_UA)
.addHeader("Origin", origin)
.build();
webSocketState = WebSocketState.CONNECTING;
this.webSocket = client.newWebSocket(request, webSocketListener);
webSocketState = WebSocketState.CONNECTED;
sendConfig(Objects.requireNonNull(this.webSocket), new TtsConfig.Builder(APP.getInt(Constants.AUDIO_FORMAT_INDEX, 0)).build());

}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/me/ag2s/tts/services/TtsActorManger.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ private TtsActorManger() {
actors.add(new TtsActor("云枫", "zh-CN-YunfengNeural", "zh-CN", false, "" + previewNote));
actors.add(new TtsActor("云皓", "zh-CN-YunhaoNeural", "zh-CN", false, "" + previewNote));
actors.add(new TtsActor("云健", "zh-CN-YunjianNeural", "zh-CN", false, "适合影视和体育解说," + previewNote));
actors.add(new TtsActor("云泽", "zh-CN-YunzeNeural", "zh-CN", false, "老年男声," + previewNote));
actors.add(new TtsActor("云夏", "zh-CN-YunxiaNeural", "zh-CN", false, "少年年男声," + previewNote));


actors.add(new TtsActor("晓涵", "zh-CN-XiaohanNeural", "zh-CN", true, "温暖、甜美、富有感情的声音,可用于许多对话场景。"));
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/me/ag2s/tts/services/TtsFormatManger.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public static TtsFormatManger getInstance() {

public TtsFormatManger() {
formats = new ArrayList<>();
this.formats.add(new TtsOutputFormat(TtsOutputFormat.TAG + "audio-24khz-48kbitrate-mono-mp3", 24000, AudioFormat.ENCODING_PCM_16BIT, true));
this.formats.add(new TtsOutputFormat(TtsOutputFormat.TAG + "audio-24khz-96kbitrate-mono-mp3", 24000, AudioFormat.ENCODING_PCM_16BIT, true));
this.formats.add(new TtsOutputFormat(TtsOutputFormat.TAG + "webm-24khz-16bit-mono-opus", 24000 * 2, AudioFormat.ENCODING_PCM_16BIT, true));

this.formats.add(new TtsOutputFormat("raw-16khz-16bit-mono-pcm", 16000, AudioFormat.ENCODING_PCM_16BIT));
this.formats.add(new TtsOutputFormat("raw-24khz-16bit-mono-pcm", 24000, AudioFormat.ENCODING_PCM_16BIT));
this.formats.add(new TtsOutputFormat("raw-48khz-16bit-mono-pcm", 48000, AudioFormat.ENCODING_PCM_16BIT));
Expand All @@ -45,8 +49,6 @@ public TtsFormatManger() {
this.formats.add(new TtsOutputFormat("audio-16khz-128kbitrate-mono-mp3", 16000, AudioFormat.ENCODING_PCM_16BIT, true));


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

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

//下面的几个不能正确的被MediaCodec解码

this.formats.add(new TtsOutputFormat("ogg-16khz-16bit-mono-opus", 16000 * 3, AudioFormat.ENCODING_PCM_16BIT, true));
this.formats.add(new TtsOutputFormat("ogg-24khz-16bit-mono-opus", 24000 * 2, AudioFormat.ENCODING_PCM_16BIT, true));
this.formats.add(new TtsOutputFormat("ogg-48khz-16bit-mono-opus", 48000, AudioFormat.ENCODING_PCM_16BIT, true));

this.formats.add(new TtsOutputFormat("webm-16khz-16bit-mono-opus", 16000 * 3, AudioFormat.ENCODING_PCM_16BIT, true));
this.formats.add(new TtsOutputFormat("webm-24khz-16bit-mono-opus", 24000 * 2, AudioFormat.ENCODING_PCM_16BIT, true));

//this.formats.add(new TtsOutputFormat("webm-48khz-16bit-mono-opus",48000,AudioFormat.ENCODING_PCM_16BIT,true));


Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/me/ag2s/tts/services/TtsOutputFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jetbrains.annotations.NotNull;

public class TtsOutputFormat {
public static final String TAG = "\uD83D\uDC96";
@NonNull
public final String name;
@NonNull
Expand All @@ -25,7 +26,13 @@ public TtsOutputFormat(@NonNull String name, int hz, int bitRate) {

public TtsOutputFormat(@NonNull String name, int hz, int bitRate, boolean needDecode) {
this.name = name;
this.value = name;
if (name.contains(TAG)) {
this.value = name.substring(TAG.length());
} else {
this.value = name;
}


this.HZ = hz;
this.BitRate = (byte) bitRate;
this.needDecode = needDecode;
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/me/ag2s/tts/services/WebSocketState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.ag2s.tts.services;

public enum WebSocketState {
OFFLINE,//断线
CONNECTED,//已连接
CONNECTING //连接中
}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
buildscript {
ext{
agp_version= '7.2.1'
kotlin_version = '1.7.0'
okhttp_version= '5.0.0-alpha.9'
okio_version="3.1.0"
kotlin_version = '1.7.10'
okhttp_version= '5.0.0-alpha.10'
okio_version="3.2.0"
}
}
plugins {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 06 22:19:25 CST 2022
#Sun Jul 17 20:47:45 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Binary file added release/TTS_release_v0.2_202207172121.apk
Binary file not shown.
Binary file added release/TTS_release_v0.2_202207172121.apk.idsig
Binary file not shown.
4 changes: 2 additions & 2 deletions release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "0.2_202206162158",
"outputFile": "TTS_release_v0.2_202206162158.apk"
"versionName": "0.2_202207172121",
"outputFile": "TTS_release_v0.2_202207172121.apk"
}
],
"elementType": "File"
Expand Down

0 comments on commit 38af594

Please sign in to comment.