File size: 1,851 Bytes
1c7cbff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09b20e1
1c7cbff
 
 
 
 
 
 
 
 
 
5966f2d
1c7cbff
09b20e1
1c7cbff
5966f2d
1c7cbff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775119b
1c7cbff
 
 
 
 
 
 
 
701a921
1c7cbff
 
 
 
 
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
69
import os
import spaces
from huggingface_hub import login

from goai_helpers.goai_traduction import goai_traduction
from goai_helpers.goai_tts2 import MooreTTS, text_to_speech
from goai_helpers.goai_tts import goai_tts


# authentification
auth_token = os.getenv('HF_SPACE_TOKEN')
login(token=auth_token)


# gradio interface text to speech function
@spaces.GPU
def goai_many_tts(
        text,
        tts_model,
        reference_speaker,
        reference_audio=None,
    ):

    if "coqui" in tts_model:
        # TTS pipeline
        tts = MooreTTS(tts_model)
        reference_speaker = os.path.join("./exples_voix", reference_speaker)

        # convert translated text to speech with reference audio
        if reference_audio is not None:
            audio_array, sampling_rate = text_to_speech(tts, text, reference_speaker, reference_audio)
        else:
            audio_array, sampling_rate = text_to_speech(tts, text, reference_speaker=reference_speaker)

        return sampling_rate, audio_array.numpy()
    
    elif "mms" in tts_model:
        sample_rate, audio_data = goai_tts(text)
        return sample_rate, audio_data

    else:
        print("Erreur de modèle!!! Veuillez vérifier le modèle sélectionné.")


# gradio interface translation and text to speech function
@spaces.GPU(duration=120)
def goai_ttt_tts(
        text,
        tts_model,
        reference_speaker,
        reference_audio=None,
    ):

    # 1. TTT: Translation fr ==> mos    
    mos_text = goai_traduction(
        text, 
        src_lang="fra_Latn", 
        tgt_lang="mos_Latn"
    )
    yield mos_text, None
    
    # 2. TTS: Text to Speech
    sample_rate, audio_data = goai_many_tts(
        mos_text,
        tts_model,
        reference_speaker,
        reference_audio=reference_audio,
    )
    yield mos_text, (sample_rate, audio_data)