Skip to content

Commit 555f3fb

Browse files
systems/to_ogg.py
1 parent 526fe3b commit 555f3fb

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

do.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,23 +424,24 @@ def w(x): file.write(x)
424424
for channel in channels:
425425
if channel:
426426
os.environ['DLAL_PAN_FLIP'] = channel
427-
p = subprocess.Popen(invocation, shell=True)
428-
signal.signal(signal.SIGINT, lambda *args: p.send_signal(signal.SIGINT))
429-
p.wait()
427+
subprocess.run(invocation, shell=True, check=True)
430428
if args.stereo:
431429
name = Path(args.run[0]).stem
432430
l = Path(name + 'l.flac')
433431
r = Path(name + 'r.flac')
434432
if l.exists() and r.exists():
435433
o = name + '.flac'
436434
print(f'combining into {o}')
437-
subprocess.run([
438-
'python3',
439-
'systems/lr_combine.py',
440-
l,
441-
r,
442-
o,
443-
])
435+
subprocess.run(
436+
[
437+
'python3',
438+
'systems/lr_combine.py',
439+
l,
440+
r,
441+
o,
442+
],
443+
check=True,
444+
)
444445

445446
# ===== deploy ===== #
446447
if args.deploy:

skeleton/dlal/_sound.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ def to_i16le(self, file_path='out.i16le'):
2222
def to_flac(self, file_path='out.flac'):
2323
sf.write(file_path, self.samples, self.sample_rate, format='FLAC')
2424

25+
def to_ogg(self, file_path='out.ogg'):
26+
# soundfile crashes!
27+
# https://github.com/bastibe/python-soundfile/issues/233
28+
# https://github.com/bastibe/python-soundfile/issues/266
29+
# https://github.com/bastibe/python-soundfile/issues/396
30+
# https://github.com/bastibe/python-soundfile/issues/426
31+
# sf.write(file_path, self.samples, self.sample_rate, format='OGG')
32+
self.to_flac('tmp.flac')
33+
p = _subprocess.run(f'ffmpeg -y -i tmp.flac {file_path}'.split(), stderr=_subprocess.PIPE)
34+
if p.returncode:
35+
raise Exception(f'ffmpeg returned non-zero exit status {p.returncode}\nstderr:\n{p.stderr.decode()}')
36+
2537
def normalize(self):
2638
m = 1 / max(abs(i) for i in self.samples)
2739
self.samples = [i * m for i in self.samples]

systems/to_ogg.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import dlal
2+
3+
import argparse
4+
from pathlib import Path
5+
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument('in_path', type=Path)
8+
args = parser.parse_args()
9+
10+
sound = dlal.sound.read(args.in_path)
11+
sound.to_ogg(args.in_path.with_suffix('.ogg'))

0 commit comments

Comments
 (0)