source: ammosreader/sample_scripts/audio_reader.py@ ee95332

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

more info methods inside container added

  • Property mode set to 100644
File size: 1.1 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("Frame sizes:", dat_file.container.frame_sizes())
25 print("Homogenic:", dat_file.container.is_homogenic())
26 pcm_data = dat_file.pcm_for_channel(0)
27 print("PCM data size total:", len(pcm_data))
28 data = AudioSegment.from_raw(io.BytesIO(pcm_data),
29 sample_width=2,
30 frame_rate=22050,
31 channels=1)
32 print("Start playing audio")
33 play(data)
Note: See TracBrowser for help on using the repository browser.