]> git.0d.be Git - django-panik-emissions.git/commitdiff
create-sound-waveforms: adapt to python3
authorFrédéric Péters <fpeters@0d.be>
Thu, 10 Oct 2019 12:22:44 +0000 (14:22 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 10 Oct 2019 12:22:44 +0000 (14:22 +0200)
emissions/management/commands/create-sound-waveforms.py

index e3f59549688c0a04902ebfae72be1d525b75b01e..766f5b486cdd1fc30c30624416d29e2ca3bbdf50 100644 (file)
@@ -4,6 +4,7 @@ import subprocess
 import numpy as np
 
 from django.core.management.base import BaseCommand, CommandError
+from django.utils import six
 
 from ...models import SoundFile
 
@@ -52,5 +53,8 @@ class Command(BaseCommand):
                 '-e' 'unsigned-integer', '-b', '8', '-']
         wave_array = subprocess.check_output(cmd)
         # reduce to 200 samples of max positive value
-        wave_reduced = [max(x) for x in np.array_split(np.array([max(0, ord(x)-128) for x in wave_array]), 200)]
-        json.dump(wave_reduced, file(file_path, 'w'))
+        if six.PY3:
+            wave_reduced = [int(max(x)) for x in np.array_split(np.array([max(0, x-128) for x in wave_array]), 200)]
+        else:
+            wave_reduced = [max(x) for x in np.array_split(np.array([max(0, ord(x)-128) for x in wave_array]), 200)]
+        json.dump(wave_reduced, open(file_path, 'w'))