source: ammosreader/sample_scripts/audio_reader.py@ bcacddc

AmmosSource guix
Last change on this file since bcacddc 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
RevLine 
[1e781ba]1import sys
[6059ec7]2import io
3from pydub import AudioSegment
4from pydub.playback import play
5
[ec7df22]6from ammosreader.AmmosAudioReader import AmmosAudioReader
[1e781ba]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()
[6059ec7]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())
[6d0f203]22 print("Frequencies", dat_file.container.frequencies())
23 print("Frame types:", dat_file.container.frame_types())
[bcacddc]24 print("Unique frame sizes", dat_file.container.unique_frame_sizes())
25 print("Total frame size:", sum(dat_file.container.frame_sizes()))
[6d0f203]26 print("Homogenic:", dat_file.container.is_homogenic())
[6059ec7]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)
[d62906b]33 print("Start playing audio")
[6059ec7]34 play(data)
Note: See TracBrowser for help on using the repository browser.