Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ag2s20150909 committed Jan 1, 2025
1 parent 974eb2c commit ddc3d4c
Show file tree
Hide file tree
Showing 25 changed files with 40,792 additions and 21,821 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/actions/setup-gradle@v4

- name: Build With Gradle
run: |
chmod +x gradlew
./gradlew assemblerelease --build-cache --parallel --daemon --warning-mode all
./gradlew assemblerelease --build-cache --parallel --warning-mode all
- name: Get VerName
run: |
echo "ver_name=$(grep 'versionName' release/output-metadata.json | cut -d\" -f4)" >> $GITHUB_ENV
- name: Upload App To Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: TTS_${{ env.ver_name }}
path: ${{ github.workspace }}/release/*
- name: Release
uses: softprops/action-gh-release@c9b46fe7aad9f02afd89b12450b780f52dacfb2d
uses: softprops/action-gh-release@v2
with:
name: TTS_${{ env.ver_name }}
tag_name: ${{ env.ver_name }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/actions/setup-gradle@v4

- name: Build With Gradle
run: |
chmod +x gradlew
./gradlew assemblerelease --build-cache --parallel --daemon --warning-mode all
./gradlew assemblerelease --build-cache --parallel --warning-mode all
- name: Get VerName
run: |
echo "ver_name=$(grep 'versionName' release/output-metadata.json | cut -d\" -f4)" >> $GITHUB_ENV
- name: Upload App To Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: TTS_${{ env.ver_name }}
path: ${{ github.workspace }}/release/*
46 changes: 23 additions & 23 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
plugins {
id 'com.android.application'
alias(libs.plugins.android.application)
}
static def releaseTime() {
return new Date().format("yyyyMMddHHmm", TimeZone.getTimeZone("GMT+08:00"))
}

android {
compileSdk 34
buildToolsVersion = '34.0.0'
compileSdk = 35
buildToolsVersion = '35.0.0'
//签名设置
signingConfigs {
release {
keyAlias 'key'
keyPassword '1234567890'
storeFile file('../public.jks')
storePassword '1234567890'
v1SigningEnabled true
v2SigningEnabled true
v1SigningEnabled =true
v2SigningEnabled =true
enableV3Signing = true
enableV4Signing = true
}
Expand All @@ -30,8 +30,8 @@ android {

defaultConfig {
applicationId "me.ag2s.tts"
minSdk 21
targetSdk 33
minSdk =21
targetSdk =35
versionCode 1
versionName "0.2_${releaseTime()}"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -42,25 +42,25 @@ android {
release {
minifyEnabled true
// 启用资源缩减
shrinkResources true
shrinkResources =true
// Zipalign优化
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
signingConfig =signingConfigs.release
}
debug {
minifyEnabled false
// 启用资源缩减
shrinkResources false
shrinkResources =false
// Zipalign优化
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
signingConfig =signingConfigs.debug
}
}

buildFeatures {
viewBinding true
viewBinding = true
}


Expand All @@ -72,12 +72,12 @@ android {
targetCompatibility JavaVersion.VERSION_11
}
dependenciesInfo {
includeInApk true
includeInBundle false
includeInApk = true
includeInBundle = false
}
namespace 'me.ag2s.tts'
namespace = 'me.ag2s.tts'

android.applicationVariants.all {
android.applicationVariants.configureEach {
variant ->

def name = ((project.name != "app") ? project.name : rootProject.name.replace(" ", "")) + "_" + variant.buildType.name + "_" + "v" + variant.versionName + ".apk"
Expand Down Expand Up @@ -134,18 +134,18 @@ dependencies {

//coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:1.1.5')

implementation "androidx.recyclerview:recyclerview:1.3.2"
implementation libs.androidx.recyclerview
//implementation 'org.conscrypt:conscrypt-android:2.5.2'
//An HTTP & HTTP/2 client for Android and Java applications.
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:$okhttp_version"
implementation "com.squareup.okio:okio:$okio_version"
implementation libs.okhttp
implementation libs.okhttp.dnsoverhttps
implementation libs.okio


testImplementation 'junit:junit:4.13.2'
testImplementation libs.junit

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core

}

10 changes: 4 additions & 6 deletions app/src/main/java/me/ag2s/tts/APP.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ public static okhttp3.OkHttpClient getOkHttpClient() {
new SharedPrefsCookiePersistor(getContext())))
.pingInterval(20, TimeUnit.SECONDS) // 设置 PING 帧发送间隔
.fastFallback(true)
.dns(s -> {
// if("speech.platform.bing.com".equals(s)){
// s="cn.bing.com";
// }
return getDns().lookup(s);
})
// .dns(s -> {
//
// return getDns().lookup(s);
// })
.build();
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/me/ag2s/tts/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());


connectToText2Speech();


Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/me/ag2s/tts/services/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package me.ag2s.tts.services;

import java.util.UUID;

import me.ag2s.tts.utils.CommonTool;

public final class Constants {
/**
* 是否使用自定义语音
Expand Down Expand Up @@ -56,8 +60,25 @@ public final class Constants {
//public static final String[] SUPPORT_LOC={"zh-CN","zh-HK","zh-TW","ja-JP","ko-KR","ar-EG","ar-SA","bg-BG","ca-ES","cs-CZ","cy-GB","da-DK","de-AT","de-CH","de-DE","el-GR","en-AU","en-CA","en-GB","en-HK","en-IE","en-IN","en-NZ","en-PH","en-SG","en-US","en-ZA","es-AR","es-CO","es-ES","es-MX","es-US","et-EE","fi-FI","fr-BE","fr-CA","fr-CH","fr-FR","ga-IE","gu-IN","he-IL","hi-IN","hr-HR","hu-HU","id-ID","it-IT","lt-LT","lv-LV","mr-IN","ms-MY","mt-MT","nb-NO","nl-BE","nl-NL","pl-PL","pt-BR","pt-PT","ro-RO","ru-RU","sk-SK","sl-SI","sv-SE","sw-KE","ta-IN","te-IN","th-TH","tr-TR","uk-UA","ur-PK","vi-VN"};


public static String buildEdgeUrl(){
StringBuilder sb=new StringBuilder(EDGE_BASE_URL);
sb.append("?TrustedClientToken=").append(TOKEN);
sb.append("&Sec-MS-GEC=").append(SecTool.getSecMsGec());
sb.append("&Sec-MS-GEC-Version=1-").append(EDGE_VERSION);
sb.append("&ConnectionId=").append( UUID.randomUUID().toString().toUpperCase());
return sb.toString();

}





private static final String EDGE_VERSION ="131.0.0.0";

public static final String TOKEN="6A5AA1D4EAFF4E9FB37E23D68491D6F4";
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/121.0.0.0 Safari/537.36 Edg/121.0.0.0";
public static final String EDGE_URL = "https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=6A5AA1D4EAFF4E9FB37E23D68491D6F4";
public static final String EDGE_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/"+EDGE_ORIGIN+" Safari/537.36 Edg/"+EDGE_ORIGIN;
private static final String EDGE_BASE_URL = "wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1";

}
20 changes: 20 additions & 0 deletions app/src/main/java/me/ag2s/tts/services/SecTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.ag2s.tts.services;

import static me.ag2s.tts.utils.CommonTool.sha256Encode;

import java.math.BigInteger;

public class SecTool {

public static String getSecMsGec(){
return sha256Encode(getTicks()+Constants.TOKEN).toUpperCase();
}

private static long getTicks(){
BigInteger seed = BigInteger.valueOf(System.currentTimeMillis());
seed=seed.multiply(BigInteger.valueOf(10000));
seed=seed.add(new BigInteger("116444736000000000"));
seed=seed.subtract(seed.mod(BigInteger.valueOf(3000000000L)));
return seed.longValue();
}
}
78 changes: 46 additions & 32 deletions app/src/main/java/me/ag2s/tts/services/TTSService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.speech.tts.Voice;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebSettings;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -213,10 +214,17 @@ public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response) {
}
};


public TTSService() {
client = getOkHttpClient();
}


private String getEdgeVersion(){
String ua=WebSettings.getDefaultUserAgent(this);
return ua.substring(0,ua.indexOf('.'))+".0.0.0";
}

private static final String ACTION_STOP_SERVICE = "action_stop_service";


Expand Down Expand Up @@ -441,39 +449,41 @@ private synchronized void doDecode(@NonNull SynthesisCallback cb, @SuppressWarni
//Log.d(TAG, ByteString.of(trackFormat.getByteBuffer("csd-0")).hex());


Buffer buf = new Buffer();
// Magic Signature:固定头,占8个字节,为字符串OpusHead
buf.write("OpusHead".getBytes(StandardCharsets.UTF_8));
// Version:版本号,占1字节,固定为0x01
buf.writeByte(1);
// Channel Count:通道数,占1字节,根据音频流通道自行设置,如0x02
buf.writeByte(1);
// Pre-skip:回放的时候从解码器中丢弃的samples数量,占2字节,为小端模式,默认设置0x00,
buf.writeShortLe(0);
// Input Sample Rate (Hz):音频流的Sample Rate,占4字节,为小端模式,根据实际情况自行设置
buf.writeIntLe(currentFormat.HZ);
//Output Gain:输出增益,占2字节,为小端模式,没有用到默认设置0x00, 0x00就好
buf.writeShortLe(0);
// Channel Mapping Family:通道映射系列,占1字节,默认设置0x00就好
buf.writeByte(0);
//Channel Mapping Table:可选参数,上面的Family默认设置0x00的时候可忽略


if (BuildConfig.DEBUG) {
Log.e(TAG, trackFormat.getByteBuffer("csd-1").order(ByteOrder.nativeOrder()).getLong() + "");
Log.e(TAG, trackFormat.getByteBuffer("csd-2").order(ByteOrder.nativeOrder()).getLong() + "");
Log.e(TAG, ByteString.of(trackFormat.getByteBuffer("csd-2").array()).hex());
try(Buffer buf = new Buffer();) {
// Magic Signature:固定头,占8个字节,为字符串OpusHead
buf.write("OpusHead".getBytes(StandardCharsets.UTF_8));
// Version:版本号,占1字节,固定为0x01
buf.writeByte(1);
// Channel Count:通道数,占1字节,根据音频流通道自行设置,如0x02
buf.writeByte(1);
// Pre-skip:回放的时候从解码器中丢弃的samples数量,占2字节,为小端模式,默认设置0x00,
buf.writeShortLe(0);
// Input Sample Rate (Hz):音频流的Sample Rate,占4字节,为小端模式,根据实际情况自行设置
buf.writeIntLe(currentFormat.HZ);
//Output Gain:输出增益,占2字节,为小端模式,没有用到默认设置0x00, 0x00就好
buf.writeShortLe(0);
// Channel Mapping Family:通道映射系列,占1字节,默认设置0x00就好
buf.writeByte(0);
//Channel Mapping Table:可选参数,上面的Family默认设置0x00的时候可忽略


// if (BuildConfig.DEBUG) {
// Log.e(TAG, trackFormat.getByteBuffer("csd-1").order(ByteOrder.nativeOrder()).getLong() + "");
// Log.e(TAG, trackFormat.getByteBuffer("csd-2").order(ByteOrder.nativeOrder()).getLong() + "");
// Log.e(TAG, ByteString.of(trackFormat.getByteBuffer("csd-2").array()).hex());
// }

byte[] csd1bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte[] csd2bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
ByteString hd = buf.readByteString();
ByteBuffer csd0 = ByteBuffer.wrap(hd.toByteArray());
trackFormat.setByteBuffer("csd-0", csd0);
ByteBuffer csd1 = ByteBuffer.wrap(csd1bytes);
trackFormat.setByteBuffer("csd-1", csd1);
ByteBuffer csd2 = ByteBuffer.wrap(csd2bytes);
trackFormat.setByteBuffer("csd-2", csd2);
}

byte[] csd1bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte[] csd2bytes = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
ByteString hd = buf.readByteString();
ByteBuffer csd0 = ByteBuffer.wrap(hd.toByteArray());
trackFormat.setByteBuffer("csd-0", csd0);
ByteBuffer csd1 = ByteBuffer.wrap(csd1bytes);
trackFormat.setByteBuffer("csd-1", csd1);
ByteBuffer csd2 = ByteBuffer.wrap(csd2bytes);
trackFormat.setByteBuffer("csd-2", csd2);

}

Expand Down Expand Up @@ -571,6 +581,9 @@ private synchronized void doUnDecode(@NonNull SynthesisCallback cb, @SuppressWar
}





/**
* 获取或者创建WS
* WebSocket
Expand All @@ -596,10 +609,11 @@ public synchronized WebSocket getOrCreateWs() {
origin = "https://azure.microsoft.com";
isPreview = true;
} else {
url = Constants.EDGE_URL;
url = Constants.buildEdgeUrl();
isPreview = false;
origin = Constants.EDGE_ORIGIN;
}
Log.e(TAG,url);
Request request = new Request.Builder()
.url(url)
//.header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6")
Expand Down
Loading

0 comments on commit ddc3d4c

Please sign in to comment.