Work around lack of scikits.audiolab support on Python 3.
authorBen Sturmfels <ben@sturm.com.au>
Thu, 12 Sep 2019 09:58:32 +0000 (19:58 +1000)
committerBen Sturmfels <ben@sturm.com.au>
Thu, 12 Sep 2019 09:59:11 +0000 (19:59 +1000)
docs/source/siteadmin/media-types.rst
extlib/freesound/audioprocessing.py

index 8f9239be7b8655cdd35c3fb247d93e76bfdc73eb..e06739ec8f5c71cb1312b0ca080c8fd867d9e6ae 100644 (file)
@@ -131,10 +131,13 @@ To install these on Debianoid systems, run::
     not compile it with alsa support. Alsa support is not necessary for the GNU
     MediaGoblin application.
 
-Then install ``scikits.audiolab`` for the spectrograms::
+If you're running Python 2, install ``scikits.audiolab`` for the spectrograms::
 
     ./bin/pip install scikits.audiolab
 
+Audio spectrograms are currently not available on Python 3, since scikits.audiolab
+does not provide Python 3 support.
+
 Add ``[[mediagoblin.media_types.audio]]`` under the ``[plugins]`` section in your
 ``mediagoblin.ini`` and restart MediaGoblin.
 
index 7ef8d5d48f662c579de02c54aba8a6109588b8b0..b9a96a970e3e0596c1ccb670e6504100c721d39a 100644 (file)
@@ -44,6 +44,31 @@ try:
     import scikits.audiolab as audiolab
 except ImportError:
     print("WARNING: audiolab is not installed so wav2png will not work")
+
+    # Hack to prevent errors when uploading audio files. The issue is that
+    # scikits.audiolab does not support Python 3. By replacing it with a mock
+    # implementation here, we can accept audio files, but we won't get the nice
+    # waveform image.
+    import six
+    if six.PY3:
+        class MockSndfile(object):
+            def __init__(self, *args, **kwargs):
+                self.nframes = 0
+                self.channels = 1
+                self.samplerate = 44100
+
+            def read_frames(self, *args):
+                return []
+
+            def seek(self, *args):
+                return
+
+            def close(self):
+                return
+        import unittest.mock as mock
+        audiolab = mock.Mock()
+        audiolab.Sndfile = MockSndfile
+
 import subprocess
 
 class AudioProcessingException(Exception):