Beispiel #1
0
def speaker_wav(wav_fn, alignment_path, speaker):
    basename = ".".join(os.path.basename(wav_fn).split('.')[:-1])

    alignment = json.load(open(alignment_path, 'r'))["words"]

    c = C.Composition(channels=1)
    t = C.Track(wav_fn, speaker)
    c.add_track(t)

    score_loc = 0.0
    start = None
    end = None
    for word in alignment:
        if "speaker" in word:
            if word["speaker"] == speaker:
                if start is None:
                    start = word["start"]
                end = word["end"]
            else:
                if start is not None:
                    seg = C.Segment(t, start, start, end - start)
                    c.add_segment(seg)
                    start = None
                    end = None
    if start is not None:
        seg = C.Segment(t, start, start, word["end"] - start)
        c.add_segment(seg)

    out_fn = "static/speechtracks/%s-%s" % (basename, speaker)

    c.export(
        min_length=t.duration,
        filename=out_fn,
        channels=1,
        filetype='wav',
        samplerate=t.samplerate,
        separate_tracks=False)

    return out_fn + ".wav"
Beispiel #2
0
    def find_loop(self, start_time, end_time):
        graph = self.graph

        # create a subgraph with just the nodes in the time frame
        span_nodes = []
        for n in graph.nodes(data=True):
            if float(n[0]) > start_time and float(n[0]) < end_time:
                span_nodes.append(n[0])
        subgraph = graph.subgraph(span_nodes)
        cycles = nx.simple_cycles(subgraph)
        if len(cycles) == 0:
            print "There are no loops in this time span. Alas!"
            return
        longest_cycle = max(cycles, key=lambda x: len(x))
        print "Longest cycle:", longest_cycle

        # compose the audio
        wav_fn = ".".join(self.filename.split('.')[:-1]) + '.wav'

        try:
            with open(wav_fn) as f:
                pass
        except IOError as e:
            # convert to wav
            subprocess.call('lame --decode "%s"' % self.filename, shell=True)

        track = C.Track(wav_fn, "song to remix")
        c = C.Composition(tracks=[track])

        score_loc = 0.0

        for i, node in enumerate(longest_cycle[:-1]):
            for edge in subgraph.edges_iter(nbunch=[node], data=True):
                if edge[1] == longest_cycle[i + 1]:
                    segment = C.Segment(track, score_loc, node,
                                        edge[2]["duration"])
                    c.add_score_segment(segment)
                    score_loc += edge[2]["duration"]
                    break

        c.output_score(adjust_dynamics=False,
                       filename="boom",
                       channels=2,
                       filetype='wav',
                       separate_tracks=False)
Beispiel #3
0
c = C.Composition(channels=1)
t = C.Track(wav_fn, speaker)
c.add_track(t)

score_loc = 0.0
start = None
end = None
for word in transcript:
    if "speaker" in word:
        if word["speaker"] == speaker:
            if start is None:
                start = word["start"]
            end = word["end"]
        else:
            if start is not None:
                seg = C.Segment(t, start, start, end - start)
                c.add_score_segment(seg)
                start = None
                end = None
if start is not None:
    seg = C.Segment(t, start, start, word["end"] - start)
    c.add_score_segment(seg)

c.output_score(adjust_dynamics=False,
               min_length=t.duration,
               filename="static/speechtracks/%s-%s" % (basename, speaker),
               channels=1,
               filetype='wav',
               samplerate=t.samplerate,
               separate_tracks=False)