How to use the audiofile.AudioFile function in audiofile

To help you get started, we’ve selected a few audiofile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shadyabhi / pLibraryOrganizer / pLibraryOrganizer.py View on Github external
#Delete the directory if its empty in the beginning itself
            if not filenames:
                try:
                    os.rmdir(dirpath)
                except OSError: pass

                if self.args.verbose: 
                    logger.debug(dirpath + "deleted as its empty")
                        
            for mp3_file in filenames:
                #Operate only on mp3s
                if mp3_file[-3:] != "mp3": 
                    continue
                files_done += 1
                src = os.path.join(dirpath, mp3_file)
                music_file = audiofile.AudioFile(src)
                
                meta_data = [music_file.getArtist(), music_file.getAlbum(), music_file.getTitle()]
                
                #Replace metadata if required. like the shitty www.songs.pk.
                #Artist
                if self.args.editartist is not None:
                    meta_data[0] = meta_data[0].replace(self.args.editartist[0],self.args.editartist[1])
                    music_file.setArtist(meta_data[0])
                #Album
                if self.args.editalbum is not None:
                    meta_data[1] = meta_data[1].replace(self.args.editalbum[0],self.args.editalbum[1])
                    music_file.setAlbum(meta_data[1])
                #Title
                if self.args.edittitle is not None:
                    meta_data[2] = meta_data[2].replace(self.args.edittitle[0],self.args.edittitle[1])
                    music_file.setTitle(meta_data[2])
github Pezz89 / PySoundConcat / src / sppysound / pitch_shift.py View on Github external
overwrite_existing=True,
        mode='w',
        channels=1,
    )
    # Write grain to be shifted to file
    shift_input.write_frames(sigin)
    # Close file
    del shift_input

    cents = 1200. * np.log2(pitch)
    p_shift_args = ["sox", input_filepath, output_filepath, "pitch", str(cents)]

    p = subprocess.Popen(p_shift_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (output, err) = p.communicate()

    with AudioFile(output_filepath, mode='r') as shift_output:
        # Read result
        result = shift_output.read_grain()
    return result
github Pezz89 / PySoundConcat / src / sppysound / database.py View on Github external
raise RuntimeError("There is no match data to synthesize. The match program may need to be run first.")

        for job_ind, (name, job) in enumerate(jobs):
            # Generate output file name/path
            filename, extension = os.path.splitext(name)
            output_name = ''.join((filename, '_output', extension))
            output_path = os.path.join(self.output_db.subdirs["audio"], output_name)
            # Create audio file to save output to.
            output_config = self.config.output_file
            grain_matches = self.output_db.data["match"][name]
            # Get the grain size and overlap used for analysis.
            match_grain_size = grain_matches.attrs["grain_size"]
            match_overlap = grain_matches.attrs["overlap"]

            _grain_size = grain_size
            with AudioFile(
                output_path,
                "w",
                samplerate=output_config["samplerate"],
                format=output_config["format"],
                channels=output_config["channels"]
            ) as output:
                hop_size = (grain_size / overlap) * output.samplerate/1000
                _grain_size *= int(output.samplerate / 1000)
                output_frames = np.zeros(_grain_size*2 + (int(hop_size*len(grain_matches))))
                offset = 0
                for target_grain_ind, matches in enumerate(grain_matches):
                    # If there are multiple matches, choose a match at random
                    # from available matches.
                    match_index = np.random.randint(matches.shape[0])
                    match_db_ind, match_grain_ind = matches[match_index]
                    with self.match_db.analysed_audio[match_db_ind] as match_sample:

audiofile

Fast reading of all kind of audio files

MIT
Latest version published 3 months ago

Package Health Score

62 / 100
Full package analysis

Similar packages