Added audio processing when available
This commit is contained in:
parent
0143da127c
commit
197a42b962
|
@ -1683,11 +1683,27 @@ class SidebandApp(MDApp):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.audio_msg_mode == LXMF.AM_OPUS_OGG:
|
if self.audio_msg_mode == LXMF.AM_OPUS_OGG:
|
||||||
|
from sideband.audioproc import voice_processing
|
||||||
|
proc_path = voice_processing(self.msg_audio._file_path)
|
||||||
|
if proc_path:
|
||||||
|
self.attach_path = proc_path
|
||||||
|
os.unlink(self.msg_audio._file_path)
|
||||||
|
RNS.log("Using voice-processed OPUS data in OGG container", RNS.LOG_DEBUG)
|
||||||
|
else:
|
||||||
self.attach_path = self.msg_audio._file_path
|
self.attach_path = self.msg_audio._file_path
|
||||||
RNS.log("Using unmodified OPUS data in OGG container", RNS.LOG_DEBUG)
|
RNS.log("Using unmodified OPUS data in OGG container", RNS.LOG_DEBUG)
|
||||||
else:
|
else:
|
||||||
ap_start = time.time()
|
ap_start = time.time()
|
||||||
|
from sideband.audioproc import voice_processing
|
||||||
|
proc_path = voice_processing(self.msg_audio._file_path)
|
||||||
|
|
||||||
|
if proc_path:
|
||||||
|
opus_file = pyogg.OpusFile(proc_path)
|
||||||
|
RNS.log("Using voice-processed audio for codec2 encoding", RNS.LOG_DEBUG)
|
||||||
|
else:
|
||||||
opus_file = pyogg.OpusFile(self.msg_audio._file_path)
|
opus_file = pyogg.OpusFile(self.msg_audio._file_path)
|
||||||
|
RNS.log("Using unprocessed audio data for codec2 encoding", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
audio = AudioSegment(
|
audio = AudioSegment(
|
||||||
bytes(opus_file.as_array()),
|
bytes(opus_file.as_array()),
|
||||||
frame_rate=opus_file.frequency,
|
frame_rate=opus_file.frequency,
|
||||||
|
|
|
@ -56,7 +56,7 @@ class AndroidAudio(Audio):
|
||||||
else:
|
else:
|
||||||
self._recorder.setAudioSource(AudioSource.DEFAULT)
|
self._recorder.setAudioSource(AudioSource.DEFAULT)
|
||||||
self._recorder.setAudioSamplingRate(48000)
|
self._recorder.setAudioSamplingRate(48000)
|
||||||
self._recorder.setAudioEncodingBitRate(16000)
|
self._recorder.setAudioEncodingBitRate(12000)
|
||||||
self._recorder.setAudioChannels(1)
|
self._recorder.setAudioChannels(1)
|
||||||
self._recorder.setOutputFormat(OutputFormat.OGG)
|
self._recorder.setOutputFormat(OutputFormat.OGG)
|
||||||
self._recorder.setAudioEncoder(AudioEncoder.OPUS)
|
self._recorder.setAudioEncoder(AudioEncoder.OPUS)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
|
import sh
|
||||||
import math
|
import math
|
||||||
import time
|
import time
|
||||||
import struct
|
import struct
|
||||||
|
@ -99,6 +100,34 @@ def samples_to_wav(samples=None, file_path=None):
|
||||||
wf.writeframes(samples)
|
wf.writeframes(samples)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def voice_processing(input_path):
|
||||||
|
try:
|
||||||
|
ffmpeg = None
|
||||||
|
ffmpeg = sh.ffmpeg
|
||||||
|
if ffmpeg:
|
||||||
|
filters = "highpass=f=250, lowpass=f=3000,speechnorm=e=12.5:r=0.0001:l=1"
|
||||||
|
output_bitrate = "12k"
|
||||||
|
opus_apptype = "audio"
|
||||||
|
output_path = input_path.replace(".ogg","")+".p.ogg"
|
||||||
|
args = [
|
||||||
|
"-i", input_path, "-filter:a", filters,
|
||||||
|
"-c:a", "libopus", "-application", opus_apptype,
|
||||||
|
"-vbr", "on","-b:a", output_bitrate, output_path]
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
os.unlink(output_path)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
ffmpeg(*args)
|
||||||
|
return output_path
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Could not process audio with ffmpeg", RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
return None
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return None
|
||||||
|
|
||||||
def detect_codec2():
|
def detect_codec2():
|
||||||
try:
|
try:
|
||||||
import pycodec2
|
import pycodec2
|
||||||
|
|
Loading…
Reference in New Issue