Guest User

Untitled

a guest
Jan 17th, 2024
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | Software | 0 0
  1. import wave
  2. import array
  3.  
  4. def wav_to_raw(input_wav, output_raw):
  5.     with wave.open(input_wav, 'rb') as wav_file:
  6.         # Получаем параметры аудио
  7.         sample_width = wav_file.getsampwidth()
  8.         frame_rate = wav_file.getframerate()
  9.        
  10.         # Читаем все аудиоданные
  11.         audio_data = wav_file.readframes(wav_file.getnframes())
  12.  
  13.         # Преобразуем байты в массив
  14.         audio_array = array.array('h', audio_data)
  15.  
  16.         # Записываем данные в файл RAW
  17.         with open(output_raw, 'wb') as raw_file:
  18.             audio_array.tofile(raw_file)
  19.  
  20. # Пример использования
  21. input_wav_file = 'websdr_recording_start_2024-01-16T17_17_03Z_140.1kHz.wav'
  22. output_raw_file = 'output.raw'
  23. wav_to_raw(input_wav_file, output_raw_file)
  24.  
Advertisement
Add Comment
Please, Sign In to add comment