mirror of
https://github.com/markqvist/Sideband.git
synced 2026-04-27 22:25:39 +00:00
Handle all audio processing with LXST
This commit is contained in:
parent
6808620f0c
commit
7d5266de05
3 changed files with 34 additions and 30 deletions
|
|
@ -30,6 +30,8 @@ import RNS.vendor.umsgpack as msgpack
|
|||
from LXST._version import __version__ as lxst_version
|
||||
from LXST.Primitives.Recorders import FileRecorder
|
||||
from LXST.Primitives.Players import FilePlayer
|
||||
from LXST.Codecs import Opus
|
||||
from LXST.Filters import BandPass, AGC
|
||||
|
||||
WINDOW_DEFAULT_WIDTH = 494
|
||||
WINDOW_DEFAULT_HEIGHT = 800
|
||||
|
|
@ -2462,7 +2464,8 @@ class SidebandApp(MDApp):
|
|||
|
||||
if not hasattr(self, "ptt_recorder") or self.ptt_recorder == None:
|
||||
self.ptt_recording_path = self.sideband.rec_cache+"/ptt_recording.ogg"
|
||||
self.ptt_recorder = FileRecorder(self.ptt_recording_path)
|
||||
self.ptt_recorder = FileRecorder(self.ptt_recording_path, profile=Opus.PROFILE_VOICE_HIGH, gain=2.0,
|
||||
skip=0.075, ease_in=0.125, filters=[BandPass(300, 8500), AGC(target_level=-15.0)])
|
||||
|
||||
self.message_attach_action(attach_type="audio", nodialog=True)
|
||||
el_button = self.messages_view.ids.message_ptt_button
|
||||
|
|
@ -2562,8 +2565,9 @@ class SidebandApp(MDApp):
|
|||
def a_rec_action(sender):
|
||||
if not self.rec_dialog.recording and not self.rec_dialog.recorder:
|
||||
self.sideband.ui_started_recording()
|
||||
self.rec_dialog.recorder = FileRecorder(self.rec_dialog.file_path)
|
||||
RNS.log("Starting recording...") # TODO: Remove
|
||||
self.rec_dialog.recorder = FileRecorder(self.rec_dialog.file_path, profile=Opus.PROFILE_VOICE_HIGH, gain=2.0,
|
||||
skip=0.075, ease_in=0.125, filters=[BandPass(300, 8500), AGC(target_level=-15.0)])
|
||||
RNS.log("Starting recording...", RNS.LOG_DEBUG) # TODO: Remove
|
||||
self.rec_dialog.recording = True
|
||||
el = self.rec_dialog.rec_item.children[0].children[0]
|
||||
el.ttc = el.theme_text_color; el.tc = el.text_color
|
||||
|
|
@ -2574,10 +2578,10 @@ class SidebandApp(MDApp):
|
|||
self.rec_dialog.recorder.start()
|
||||
|
||||
else:
|
||||
RNS.log("Stopping recording...") # TODO: Remove
|
||||
RNS.log("Stopping recording...", RNS.LOG_DEBUG) # TODO: Remove
|
||||
self.rec_dialog.recorder.stop()
|
||||
self.rec_dialog.recorder = None
|
||||
RNS.log("Recording stopped") # TODO: Remove
|
||||
RNS.log("Recording stopped", RNS.LOG_DEBUG) # TODO: Remove
|
||||
self.rec_dialog.rec_item.text = "[size="+str(ss)+"]Start Recording[/size]"
|
||||
el = self.rec_dialog.rec_item.children[0].children[0]
|
||||
el.icon = "record"
|
||||
|
|
|
|||
|
|
@ -102,28 +102,30 @@ def samples_to_wav(samples=None, file_path=None):
|
|||
|
||||
def voice_processing(input_path):
|
||||
try:
|
||||
ffmpeg = None
|
||||
ffmpeg = sh.ffmpeg
|
||||
if ffmpeg:
|
||||
filters = "atrim=start=0.075, afade=t=in:st=0:d=0.085, 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
|
||||
return None
|
||||
# Moving to LXST native processing
|
||||
# ffmpeg = None
|
||||
# ffmpeg = sh.ffmpeg
|
||||
# if ffmpeg:
|
||||
# filters = "atrim=start=0.075, afade=t=in:st=0:d=0.085, 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
|
||||
|
|
|
|||
|
|
@ -5010,9 +5010,7 @@ class SidebandCore():
|
|||
temp_path = self.rec_cache+"/ptt_msg.ogg"
|
||||
from sideband.audioproc import samples_to_ogg, decode_codec2, detect_codec2
|
||||
|
||||
target_rate = 8000
|
||||
if RNS.vendor.platformutils.is_linux(): target_rate = 48000
|
||||
|
||||
target_rate = 48000
|
||||
if detect_codec2():
|
||||
if samples_to_ogg(decode_codec2(audio_field[1], audio_field[0]), temp_path, input_rate=8000, output_rate=target_rate): RNS.log("Wrote OGG file to: "+temp_path, RNS.LOG_DEBUG)
|
||||
else: RNS.log("OGG write failed", RNS.LOG_DEBUG)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue