Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio_dirs = AudioDirectory.scan(audio_dir) Return nothing #2

Open
qasimali-byte opened this issue Feb 4, 2021 · 0 comments
Open

Comments

@qasimali-byte
Copy link

qasimali-byte commented Feb 4, 2021

        import os
        
        from micmon.audio import AudioDirectory, AudioPlayer, AudioFile
        from micmon.dataset import DatasetWriter
        
        basedir = os.path.expanduser('~/BabyCare')
        audio_dir = os.path.join(basedir, 'audio/sample_1')
        print(audio_dir)  # print just [ ]
        datasets_dir = os.path.join(basedir, 'data')
        cutoff_frequencies = [250, 7500]
        
        # Scan the base audio_dir for labelled audio samples
        audio_dirs = AudioDirectory.scan(audio_dir)
        print(audio_dirs)
        
        # Play some audio samples starting from 01:00
        for audio_dir in audio_dirs:
            with AudioFile(audio_dir, start='01:00', duration=5) as reader, \
                    AudioPlayer() as player:
                for sample in reader:
                    player.play(sample)
        
        # Plot the audio and spectrum of the audio samples in the first 10 seconds
        # of each audio file.
        for audio_dir in audio_dirs:
            with AudioFile(audio_dir, start=0, duration=10) as reader:
                for sample in reader:
                    sample.plot_audio()
                    sample.plot_spectrum(low_freq=cutoff_frequencies[0],
                                         high_freq=cutoff_frequencies[1])
        
        # Save the spectrum information and labels of the samples to a
        # different compressed file for each audio file.
        for audio_dir in audio_dirs:
            dataset_file = os.path.join(datasets_dir, os.path.basename(audio_dir.path) + '.npz')
            print(f'Processing audio sample {audio_dir.path}')
        
            with AudioFile(audio_dir) as reader, \
                    DatasetWriter(dataset_file,
                                  low_freq=cutoff_frequencies[0],
                                  high_freq=cutoff_frequencies[1]) as writer:
                for sample in reader:
                    writer += sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant