Skip to content

Commit

Permalink
systems/to_ogg.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dansgithubuser committed Aug 26, 2024
1 parent 526fe3b commit 555f3fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
21 changes: 11 additions & 10 deletions do.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,24 @@ def w(x): file.write(x)
for channel in channels:
if channel:
os.environ['DLAL_PAN_FLIP'] = channel
p = subprocess.Popen(invocation, shell=True)
signal.signal(signal.SIGINT, lambda *args: p.send_signal(signal.SIGINT))
p.wait()
subprocess.run(invocation, shell=True, check=True)
if args.stereo:
name = Path(args.run[0]).stem
l = Path(name + 'l.flac')
r = Path(name + 'r.flac')
if l.exists() and r.exists():
o = name + '.flac'
print(f'combining into {o}')
subprocess.run([
'python3',
'systems/lr_combine.py',
l,
r,
o,
])
subprocess.run(
[
'python3',
'systems/lr_combine.py',
l,
r,
o,
],
check=True,
)

# ===== deploy ===== #
if args.deploy:
Expand Down
12 changes: 12 additions & 0 deletions skeleton/dlal/_sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ def to_i16le(self, file_path='out.i16le'):
def to_flac(self, file_path='out.flac'):
sf.write(file_path, self.samples, self.sample_rate, format='FLAC')

def to_ogg(self, file_path='out.ogg'):
# soundfile crashes!
# https://github.com/bastibe/python-soundfile/issues/233
# https://github.com/bastibe/python-soundfile/issues/266
# https://github.com/bastibe/python-soundfile/issues/396
# https://github.com/bastibe/python-soundfile/issues/426
# sf.write(file_path, self.samples, self.sample_rate, format='OGG')
self.to_flac('tmp.flac')
p = _subprocess.run(f'ffmpeg -y -i tmp.flac {file_path}'.split(), stderr=_subprocess.PIPE)
if p.returncode:
raise Exception(f'ffmpeg returned non-zero exit status {p.returncode}\nstderr:\n{p.stderr.decode()}')

def normalize(self):
m = 1 / max(abs(i) for i in self.samples)
self.samples = [i * m for i in self.samples]
Expand Down
11 changes: 11 additions & 0 deletions systems/to_ogg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import dlal

import argparse
from pathlib import Path

parser = argparse.ArgumentParser()
parser.add_argument('in_path', type=Path)
args = parser.parse_args()

sound = dlal.sound.read(args.in_path)
sound.to_ogg(args.in_path.with_suffix('.ogg'))

0 comments on commit 555f3fb

Please sign in to comment.