def _loadFile(fileName): sf = SoundFile(fileName) signal = sf.read() channels = sf.channels sample_rate = sf.samplerate sf.close() return signal, channels, sample_rate
def Save(cls, filename, data): channels = data.GetChannels() frames = numpy.array(channels).transpose() fileformat = audiolab.Format(type=cls.format, encoding=cls.encoding, endianness="file") soundfile = audiolab.Sndfile(filename=filename + "." + cls.ending, mode="w", format=fileformat, channels=len(channels), samplerate=int(round(data.GetSamplingRate()))) soundfile.write_frames(frames) soundfile.close()
def Load(cls, filename): name = filename.split(os.sep)[-1] soundfile = audiolab.Sndfile(filename=filename + "." + cls.ending, mode="r") frames = soundfile.read_frames(nframes=soundfile.nframes, dtype=numpy.float64) channels = tuple(frames.transpose()) if soundfile.channels == 1: channels = (channels,) labels = [] for c in range(soundfile.channels): labels.append(str(" ".join([name, str(c + 1)]))) samplingrate = soundfile.samplerate soundfile.close() return sumpf.Signal(channels=channels, samplingrate=samplingrate, labels=labels)
def generate_data(language, title, file): if language == 1: path = 'English/english' else: path = 'German/german' try: filename = f'./data/{path}/{title}/{file}' data, samplerate = sf.read(filename, dtype='float32') sf.close() except: pass try: data = data[:, 1] except: pass return data, samplerate, path