File size: 2,643 Bytes
03b76a9
 
 
d052f09
ef46557
 
 
 
 
 
 
 
 
50eafc0
d66e6d1
ef46557
 
50eafc0
0e1a6dd
 
ef46557
 
03a0d5b
 
ef46557
 
d66e6d1
 
 
 
 
 
 
ef46557
 
 
 
 
 
 
 
50eafc0
 
f7a2d31
0a65394
ef46557
d66e6d1
ef46557
 
d66e6d1
ef46557
0a65394
ef46557
0a65394
d6ab360
07cf45f
 
ef46557
07cf45f
ef46557
 
07cf45f
ef46557
07cf45f
 
ef46557
d052f09
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import wave
import gradio as gr

def get_audio_duration(audio_file):
    """Get the duration of the audio file in seconds."""
    try:
        with wave.open(audio_file, 'rb') as audio:
            frames = audio.getnframes()
            rate = audio.getframerate()
            duration = frames / float(rate)
        return duration
    except wave.Error:
        raise ValueError("Invalid audio file. Please upload a valid .wav file.")

def get_training_info(audio_file, pretrain):
    """Determine training parameters based on the duration of the audio file."""
    try:
        if not audio_file:
            raise gr.Error("Please provide an audio file :(")
            return "."
        
        duration = get_audio_duration(audio_file)
        with wave.open(audio_file, 'rb') as audio:
            sample_rate = audio.getframerate()

        training_info = {
            (0, 2): (150, f'{pretrain}'),
            (2, 3): (200, f'{pretrain}'),
            (3, 5): (250, f'{pretrain}'),
            (5, 10): (300, f'{pretrain}'),
            (10, 25): (500, f'{pretrain}'),
            (25, 45): (700, f'{pretrain}'),
            (45, 60): (1000, f'{pretrain}')
        }

        for (min_duration, max_duration), (epochs, pretrain) in training_info.items():
            if min_duration <= duration < max_duration:
                return f'You should use the **{pretrain}** pretrain with **{epochs}** epochs at **{sample_rate / 1000} kHz** sample rate. Good luck with your training!'
        
        return 'Duration is not within the specified range.'
    except ValueError as e:
        raise gr.Error(str(e))

with gr.Blocks(theme=gr.themes.Base(primary_hue="sky", secondary_hue="blue"), title="RVC TRAINING HELPER") as demo:
    with gr.Tab("Main Settings"):
        audio_input = gr.Audio(type="filepath", label="Your Audio here")
        pretraina = gr.Dropdown(choices=["OV2","Normal","TITAN","Snowie V3","RIN E3","SnowieV3 X RIN_E3","ITALIA"])
        start_button = gr.Button("Start!")
        output_text = gr.Textbox(scale=3, label="Your Output here")
        start_button.click(get_training_info, inputs=[audio_input,pretraina], outputs=[output_text])
    
    with gr.Tab("Credits"):
        gr.Markdown("### This code originally by [TheStinger](https://huggingface.co./TheStinger)<br>Edited by Blane187")

    with gr.Tab('Tutorial'):
        gr.Markdown(
            """
            ### Step by Step Guide

            1. Upload an audio file (or record yourself by tapping the mic button).
            2. Click the `Start!` button.

            And you're done!
            """
        )

    demo.launch(debug=True)