-
Notifications
You must be signed in to change notification settings - Fork 3
/
transfer.py
53 lines (43 loc) · 1.91 KB
/
transfer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding: latin-1 -*-
# Copyright 2014 Oeyvind Brandtsegg and Axel Tidemann
#
# This file is part of [self.]
#
# [self.] is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# [self.] is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with [self.]. If not, see <http://www.gnu.org/licenses/>.
''' [self.]
@author: Axel Tidemann, Øyvind Brandtsegg
@contact: [email protected], [email protected]
@license: GPL
'''
from altbrain import AudioSegment, AudioMemory
import utils
def transfer(NAPs, wavs, wav_audio_ids):
audio_memory = AudioMemory()
for audio_id, nappers in enumerate(NAPs):
for i in range(len(nappers)):
NAP = nappers[i]
if len(NAP):
clean_key, overlap_key = audio_memory._digitize(NAP)
crude_hash = utils.d_hash(NAP, hash_size=8)
fine_hash = utils.d_hash(NAP, hash_size=16)
wav_file = wavs[audio_id][i]
try:
audio_segment = AudioSegment(audio_id, crude_hash, fine_hash, wav_file, wav_audio_ids[(wav_file, audio_id)])
except:
print '{} {} barfed'.format(wav_file, audio_id)
continue
audio_memory._insert(audio_memory.NAP_intervals, clean_key, audio_segment)
audio_memory._insert(audio_memory.NAP_intervals, overlap_key, audio_segment)
audio_memory._insert(audio_memory.audio_ids, audio_id, audio_segment)
return audio_memory