SHARE
TWEET

Untitled

a guest Jun 14th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pexpect.popen_spawn import PopenSpawn
  2. import soundfile as sf
  3.  
  4.  
  5. def sox_process(samplerate=44100, channels=2):
  6.     process = PopenSpawn(
  7.         [
  8.             'sox',
  9.             # '−−multi−threaded',
  10.  
  11.             '-e', 'floating-point',
  12.             '-b', '32',
  13.             '-r', f'{samplerate}',
  14.             '-c', f'{channels}',
  15.             '-t', 'raw', '-',
  16.  
  17.             '-e', 'floating-point',
  18.             '-b', '32',
  19.             '-r', f'{samplerate}',
  20.             '-c', f'{channels}',
  21.             '-t', 'raw', '-',
  22.  
  23.             # effect parameters go here
  24.         ],
  25.     )
  26.     return process
  27.  
  28.  
  29. sox = sox_process()
  30. file = sf.SoundFile(r'C:\Users\admin\Documents\Projects\audio-player\examples\loop.wav')
  31.  
  32. bytes_in_file = 0
  33. bytes_sent_to_sox = 0
  34. bytes_received_from_sox = 0
  35.  
  36. for block in file.blocks(blocksize=4096, dtype='float32'):
  37.     chunk = block.tobytes()
  38.     bytes_in_file += len(chunk)
  39.     bytes_sent_to_sox += sox.send(chunk)
  40.  
  41. while True:
  42.     chunk = sox.read_nonblocking(size=8192, timeout=-1)
  43.     if chunk:
  44.         bytes_received_from_sox += len(chunk)
  45.     else:
  46.         break
  47.  
  48. print('done')
  49. print('in file:', bytes_in_file)
  50. print('sent to sox:', bytes_sent_to_sox)
  51. print('received from sox:', bytes_received_from_sox)
  52. print('missing:', bytes_sent_to_sox - bytes_received_from_sox)
  53.  
  54. # output:
  55. # done
  56. # in file: 925376
  57. # sent to sox: 925376
  58. # received from sox: 917504
  59. # missing: 7872
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top