Skip to content

Commit b47f77c

Browse files
committed
Merge with v2.00
2 parents 43f6f9a + 49e7f20 commit b47f77c

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ The initial download will get the models from GitHub, however <a href="https://w
6565
If you have a GitHub account and want to be notified when a new release comes out you can do so by clicking, at the top of the page, on "Watch" -> "Custom" -> "Releases" -> "Apply".
6666
<br /><br />
6767

68+
<h3>RTranslator 3.0 Coming Soon!</h3>
69+
70+
The 3.0 version of RTranslator will be funded through the [NGI Mobifree Fund](https://nlnet.nl/mobifree), a fund established by [NLnet](https://nlnet.nl).
71+
72+
Main changes of this version:
73+
- The NLLB translation model will be replaced with the option to choose between: Mozilla Bergamot models, Madlad 400 3B, and HY-MT 1.5 1.8B. All these models have better translation quality than NLLB 54B, similar to Google Translate (with HY-MT 1.5 1.8B having much better scores than Google Translate).
74+
- MLKit will be replaced, making RTranslator 100% open source.
75+
- Various techniques will be added to improve translation quality, including: beam search, multilingual dictionaries, Tatoeba integration, and more.
76+
- The app will be released on Play Store and F-Droid.
77+
- A self-hosted web version of the app for text translation using Mozilla models will be made available.
78+
79+
The first beta of this version will be released between June and August 2026. Stay tuned 🚀
80+
81+
<img src="https://nlnet.nl/logo/banner.svg" width="200px">
82+
<br />
83+
6884
<h3>What's new in version 2.1</h3>
6985

7086
- **New GUI!** Designed by [Chiara Chindamo](https://www.linkedin.com/in/chiara-chindamo-946053234/).
@@ -186,6 +202,7 @@ If you want to contribute to this project, first of all, thank you 🚀
186202
If you don't know where to start, go check the [to-do list](https://github.com/niedev/RTranslator/blob/v2.00/TODO_LIST.md), and in any case, before starting, read the [contribution guidelines](https://github.com/niedev/RTranslator/blob/v2.00/CONTRIBUTING.md).
187203
<br /><br />
188204

205+
189206
<h3>Bugs and problems</h3>
190207
I remind you that the app is still in beta. The bugs found are the following:
191208

app/src/main/java/nie/translator/rtranslator/voice_translation/neural_networks/voice/Recorder.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import android.media.AudioManager;
2727
import android.media.AudioRecord;
2828
import android.media.MediaRecorder;
29+
import android.os.Build;
2930
import android.util.Log;
31+
import android.widget.Toast;
3032

3133
import androidx.annotation.NonNull;
3234
import androidx.annotation.Nullable;
@@ -57,7 +59,7 @@ public class Recorder {
5759
private boolean isManualMode = false;
5860
public static final int[] SAMPLE_RATE_CANDIDATES = new int[]{16000};
5961
private static final int CHANNEL = AudioFormat.CHANNEL_IN_MONO;
60-
private static final int ENCODING = AudioFormat.ENCODING_PCM_FLOAT; //original: AudioFormat.ENCODING_PCM_16BIT
62+
private static int ENCODING;
6163
public static final int MAX_AMPLITUDE_THRESHOLD = 15000;
6264
public static final int DEFAULT_AMPLITUDE_THRESHOLD = 2000; //original: 1500
6365
public static final int MIN_AMPLITUDE_THRESHOLD = 400;
@@ -75,6 +77,7 @@ public class Recorder {
7577
private Thread mThread;
7678
private int mPrevBufferMaxSize; //the size of the mPrevBuffer (It depends on the settings of the app (prevVoiceDuration))
7779
private float[] mBuffer;
80+
private short[] mBufferShort;
7881
private int readSize; //must be smaller than mBuffer.length or the circular mBuffer array will not work
7982
private int headIndex;
8083
private int tailIndex;
@@ -107,6 +110,13 @@ public Recorder(Global global, boolean useBluetoothHeadset, @NonNull Callback ca
107110
mCallback.setRecorder(this);
108111
this.vad = vad;
109112

113+
// set the encoding
114+
if(Build.MANUFACTURER.equalsIgnoreCase("vivo")){
115+
ENCODING = AudioFormat.ENCODING_PCM_16BIT; //this is to avoid a bug where on Vivo phones the audio recording wouldn't work
116+
}else{
117+
ENCODING = AudioFormat.ENCODING_PCM_FLOAT;
118+
}
119+
110120
// Try to create a new recording session.
111121
mAudioRecord = createAudioRecord();
112122
if (mAudioRecord == null) {
@@ -266,6 +276,7 @@ private AudioRecord createAudioRecord() {
266276
if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
267277
readSize = (minSizeInBytes/4)*2;
268278
mBuffer = new float[((MAX_SPEECH_LENGTH_MILLIS+1000)/1000)*sampleRate]; //the buffer size will be larger (by one second) than the audio data of duration MAX_SPEECH_LENGTH_MILLIS
279+
mBufferShort = new short[((MAX_SPEECH_LENGTH_MILLIS+1000)/1000)*sampleRate];
269280
return audioRecord;
270281
} else {
271282
audioRecord.release();
@@ -329,13 +340,13 @@ public void run() {
329340
int oldTailIndex = tailIndex;
330341
boolean jumped;
331342
if (tailIndex + readSize < mBuffer.length) {
332-
size = mAudioRecord.read(mBuffer, tailIndex, readSize, AudioRecord.READ_BLOCKING);
343+
size = readAudio(mBuffer, tailIndex, readSize);
333344
tailIndex = tailIndex + size;
334345
jumped = false;
335346
} else {
336-
size = mAudioRecord.read(mBuffer, tailIndex, mBuffer.length - tailIndex, AudioRecord.READ_BLOCKING);
347+
size = readAudio(mBuffer, tailIndex, mBuffer.length - tailIndex);
337348
tailIndex = 0;
338-
int size2 = mAudioRecord.read(mBuffer, tailIndex, readSize - size, AudioRecord.READ_BLOCKING);
349+
int size2 = readAudio(mBuffer, tailIndex, readSize - size);
339350
tailIndex = size2;
340351
size = size + size2;
341352
jumped = true;
@@ -396,6 +407,21 @@ private int getMBufferRangeSize(int begin, int end){
396407
}
397408
}
398409

410+
private int readAudio(float[] audioData, int offset, int size){
411+
if(ENCODING == AudioFormat.ENCODING_PCM_FLOAT){
412+
return mAudioRecord.read(audioData, offset, size, AudioRecord.READ_BLOCKING);
413+
}else{ //ENCODING == AudioFormat.ENCODING_PCM_16BIT
414+
int outputSize = mAudioRecord.read(mBufferShort, offset, size, AudioRecord.READ_BLOCKING);
415+
// Using the values just read in mBufferShort we convert the values to mBuffer in the ENCODING_PCM_FLOAT format
416+
// Tod od this we iterate the section just wrote of mBufferShort, convert each value from ENCODING_PCM_16BIT to ENCODING_PCM_FLOAT and insert these value in the corresponding section of mBuffer.
417+
for(int i=offset; i<offset+size; i++){
418+
//The range with ENCODING_PCM_16BIT is [-32768, 32767], while with ENCODING_PCM_FLOAT it is [-1, 1], so we convert accordingly
419+
mBuffer[i] = (float) mBufferShort[i] / 32768;
420+
}
421+
return outputSize;
422+
}
423+
}
424+
399425
private boolean isHearingVoice(byte[] buffer, int size) { //old method to measure threshold (not used)
400426
for (int i = 0; i < size - 1; i += 2) {
401427
// The buffer has LINEAR16 (2 bytes) in little endian.

0 commit comments

Comments
 (0)