File size: 1,364 Bytes
39562c5
 
 
 
 
 
78c219b
 
 
 
39562c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78c219b
 
 
 
39562c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78c219b
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
import gradio as gr
import subprocess
import tempfile
import os
import soundfile as sf

LORIS_ANALYZE = "/usr/local/bin/loris_analyze"
LORIS_MORPH = "/usr/local/bin/loris_morph"
LORIS_SYNTH = "/usr/local/bin/loris_synthesize"

def run(cmd):
    subprocess.check_call(cmd, shell=True)

def morph_audio(wav_a, wav_b, morph_amt):
    with tempfile.TemporaryDirectory() as d:
        a_wav = os.path.join(d, "a.wav")
        b_wav = os.path.join(d, "b.wav")
        a_sdif = os.path.join(d, "a.sdif")
        b_sdif = os.path.join(d, "b.sdif")
        m_sdif = os.path.join(d, "m.sdif")
        out_wav = os.path.join(d, "out.wav")

        sf.write(a_wav, wav_a[1], wav_a[0])
        sf.write(b_wav, wav_b[1], wav_b[0])

        run(f"{LORIS_ANALYZE} {a_wav} {a_sdif}")
        run(f"{LORIS_ANALYZE} {b_wav} {b_sdif}")
        run(f"{LORIS_MORPH} --alpha {morph_amt} {a_sdif} {b_sdif} {m_sdif}")
        run(f"{LORIS_SYNTH} {m_sdif} {out_wav}")

        data, sr = sf.read(out_wav)
        return sr, data

ui = gr.Interface(
    fn=morph_audio,
    inputs=[
        gr.Audio(label="Input A", type="numpy"),
        gr.Audio(label="Input B", type="numpy"),
        gr.Slider(0.0, 1.0, value=0.5, label="Morph Amount")
    ],
    outputs=gr.Audio(label="Morphed Output"),
    title="Loris Audio Morphing (SDIF)",
)

ui.launch(server_name="0.0.0.0", server_port=7860)