source: ammosreader/sample_scripts/audio_reader.py@ 577ce87

AmmosSource guix
Last change on this file since 577ce87 was bcacddc, checked in by Enrico Schwass <ennoausberlin@…>, 3 years ago

initial version of ammos_reader.py added

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import sys
2import io
3from pydub import AudioSegment
4from pydub.playback import play
5
6from ammosreader.AmmosAudioReader import AmmosAudioReader
7
8if __name__ == '__main__':
9
10 if len(sys.argv) != 2:
11 sys.exit()
12
13 file_name = sys.argv[1]
14
15 print("File name:", file_name)
16
17 dat_file = AmmosAudioReader(file_name)
18
19 dat_file.read_all_frames_left()
20 print("Sample rate:", dat_file.container.global_frames[0].global_frame_body.data_header.sample_rate)
21 print("Container size:", dat_file.container.size())
22 print("Frequencies", dat_file.container.frequencies())
23 print("Frame types:", dat_file.container.frame_types())
24 print("Unique frame sizes", dat_file.container.unique_frame_sizes())
25 print("Total frame size:", sum(dat_file.container.frame_sizes()))
26 print("Homogenic:", dat_file.container.is_homogenic())
27 pcm_data = dat_file.pcm_for_channel(0)
28 print("PCM data size total:", len(pcm_data))
29 data = AudioSegment.from_raw(io.BytesIO(pcm_data),
30 sample_width=2,
31 frame_rate=22050,
32 channels=1)
33 print("Start playing audio")
34 play(data)
Note: See TracBrowser for help on using the repository browser.