source: ammosreader/sample_scripts/audio_reader.py@ a81ab76

AmmosSource guix
Last change on this file since a81ab76 was 6059ec7, checked in by Enrico Schwass <ennoausberlin@…>, 3 years ago

accessors added - AmmosAudioDataBlock added

  • Property mode set to 100644
File size: 870 bytes
RevLine 
[1e781ba]1import sys
2import os
[6059ec7]3import io
4from pydub import AudioSegment
5from pydub.playback import play
6
[bec3119]7sys.path.append('../src/')
[1e781ba]8
[ec7df22]9from ammosreader.AmmosAudioReader import AmmosAudioReader
[1e781ba]10
11if __name__ == '__main__':
12
13 if len(sys.argv) != 2:
14 sys.exit()
15
16 file_name = sys.argv[1]
17
18 print("File name:", file_name)
19
20 dat_file = AmmosAudioReader(file_name)
21
22 dat_file.read_all_frames_left()
[6059ec7]23 print("Sample rate:", dat_file.container.global_frames[0].global_frame_body.data_header.sample_rate)
24 print("Container size:", dat_file.container.size())
25 pcm_data = dat_file.pcm_for_channel(0)
26 print("PCM data size total:", len(pcm_data))
27 data = AudioSegment.from_raw(io.BytesIO(pcm_data),
28 sample_width=2,
29 frame_rate=22050,
30 channels=1)
31 play(data)
Note: See TracBrowser for help on using the repository browser.