feat: add noise suppress and voice enhance
N-setting -> Chat -> Noise Suppress And Voice Enhance
This commit is contained in:
parent
db9abaf36b
commit
4f97ea4999
@ -100,9 +100,10 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import tw.nekomimi.nekogram.SaveToDownloadReceiver;
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
import tw.nekomimi.nekogram.NekoXConfig;
|
||||
import tw.nekomimi.nekogram.SaveToDownloadReceiver;
|
||||
import xyz.nextalone.nagram.helper.AudioEnhance;
|
||||
|
||||
public class MediaController implements AudioManager.OnAudioFocusChangeListener, NotificationCenter.NotificationCenterDelegate, SensorEventListener {
|
||||
|
||||
@ -3505,6 +3506,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
recordReplyingMsg = replyToMsg;
|
||||
recordReplyingTopMsg = replyToTopMsg;
|
||||
fileBuffer.rewind();
|
||||
AudioEnhance.INSTANCE.initVoiceEnhance(audioRecorder);
|
||||
|
||||
audioRecorder.startRecording();
|
||||
} catch (Exception e) {
|
||||
@ -3514,6 +3516,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
recordingAudioFile.delete();
|
||||
recordingAudioFile = null;
|
||||
try {
|
||||
AudioEnhance.INSTANCE.releaseVoiceEnhance();
|
||||
audioRecorder.release();
|
||||
audioRecorder = null;
|
||||
} catch (Exception e2) {
|
||||
@ -3607,6 +3610,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
requestAudioFocus(false);
|
||||
}
|
||||
try {
|
||||
AudioEnhance.INSTANCE.releaseVoiceEnhance();
|
||||
if (audioRecorder != null) {
|
||||
audioRecorder.release();
|
||||
audioRecorder = null;
|
||||
|
@ -119,6 +119,7 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati
|
||||
LocaleController.getString("combineMessageEnabled", R.string.CombineMessageEnabled),
|
||||
LocaleController.getString("combineMessageDisabled", R.string.CombineMessageDisabled)
|
||||
}, null));
|
||||
private final AbstractConfigCell audioEnhanceRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getNoiseSuppressAndVoiceEnhance()));
|
||||
private final AbstractConfigCell divider1 = cellGroup.appendCell(new ConfigCellDivider());
|
||||
private final AbstractConfigCell header2 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("AutoDownload")));
|
||||
private final AbstractConfigCell win32Row = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableAutoDownloadingWin32Executable));
|
||||
|
@ -109,6 +109,12 @@ object NaConfig {
|
||||
ConfigItem.configTypeBool,
|
||||
false
|
||||
)
|
||||
val noiseSuppressAndVoiceEnhance =
|
||||
addConfig(
|
||||
"NoiseSuppressAndVoiceEnhance",
|
||||
ConfigItem.configTypeBool,
|
||||
false
|
||||
)
|
||||
|
||||
fun addConfig(
|
||||
k: String,
|
||||
|
@ -0,0 +1,68 @@
|
||||
package xyz.nextalone.nagram.helper
|
||||
|
||||
import android.media.AudioRecord
|
||||
import android.media.audiofx.AcousticEchoCanceler
|
||||
import android.media.audiofx.AutomaticGainControl
|
||||
import android.media.audiofx.NoiseSuppressor
|
||||
import xyz.nextalone.nagram.NaConfig
|
||||
|
||||
object AudioEnhance {
|
||||
var automaticGainControl: AutomaticGainControl? =
|
||||
null
|
||||
var acousticEchoCanceler: AcousticEchoCanceler? =
|
||||
null
|
||||
var noiseSuppressor: NoiseSuppressor? =
|
||||
null
|
||||
|
||||
fun initVoiceEnhance(
|
||||
audioRecord: AudioRecord
|
||||
) {
|
||||
if (!NaConfig.noiseSuppressAndVoiceEnhance.Bool()) return
|
||||
if (AutomaticGainControl.isAvailable()) {
|
||||
automaticGainControl =
|
||||
AutomaticGainControl.create(
|
||||
audioRecord.audioSessionId
|
||||
)
|
||||
automaticGainControl?.enabled =
|
||||
true
|
||||
}
|
||||
if (AcousticEchoCanceler.isAvailable()) {
|
||||
acousticEchoCanceler =
|
||||
AcousticEchoCanceler.create(
|
||||
audioRecord.audioSessionId
|
||||
)
|
||||
acousticEchoCanceler?.enabled =
|
||||
true
|
||||
}
|
||||
if (NoiseSuppressor.isAvailable()) {
|
||||
noiseSuppressor =
|
||||
NoiseSuppressor.create(
|
||||
audioRecord.audioSessionId
|
||||
)
|
||||
noiseSuppressor?.enabled =
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fun releaseVoiceEnhance() {
|
||||
if (automaticGainControl != null) {
|
||||
automaticGainControl?.release()
|
||||
automaticGainControl =
|
||||
null
|
||||
}
|
||||
if (acousticEchoCanceler != null) {
|
||||
acousticEchoCanceler?.release()
|
||||
acousticEchoCanceler =
|
||||
null
|
||||
}
|
||||
if (noiseSuppressor != null) {
|
||||
noiseSuppressor?.release()
|
||||
noiseSuppressor =
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun isAvailable(): Boolean {
|
||||
return AutomaticGainControl.isAvailable() || NoiseSuppressor.isAvailable() || AcousticEchoCanceler.isAvailable()
|
||||
}
|
||||
}
|
@ -13,4 +13,5 @@
|
||||
<string name="TextUndoRedo">撤销/重做</string>
|
||||
<string name="TextUndo">撤销</string>
|
||||
<string name="TextRedo">重做</string>
|
||||
<string name="NoiseSuppressAndVoiceEnhance">噪音抑制和语音增强</string>
|
||||
</resources>
|
||||
|
@ -13,4 +13,5 @@
|
||||
<string name="TextUndoRedo">Undo/Redo</string>
|
||||
<string name="TextUndo">Undo</string>
|
||||
<string name="TextRedo">Redo</string>
|
||||
<string name="NoiseSuppressAndVoiceEnhance">Noise Suppress And Voice Enhance</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user