1. 2
  1.  

    1. 2

      Just in case the script doesn’t work (it didn’t work for me in msys2 in a windows terminal), you need to replace the python command at the end of a script with this line:

      python -c "import io;import sys;sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8');sys.stdout.write('P5\n$Dimensions\n255\n'+''.join([chr((ord(c)+128)&255) for c in sys.stdin.read()[::2]]))" <mp3img.gray >mp3img.pgm
      

      Basically it adds this:

      import io
      sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
      

      There’s probably a better way, but hey, if it works, it works.