-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElevenLabs.cs
85 lines (70 loc) · 2.84 KB
/
ElevenLabs.cs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Agora {
public partial class Discussion {
public class ElevenLabs
{
public ElevenLabs()
{
}
public bool Speak(Discussion discussion)
{
// récupérer le nombre de fichiers dans le dossier 'audio' pour le nom du prochain fichier
string idFile = discussion.Messages.Count.ToString();
string backup = @"
import sys
from elevenlabs_unleashed.manager import ELUAccountManager
from elevenlabs import generate, save, set_api_key, play, api
from elevenlabs_unleashed.tts import UnleashedTTS
def text_to_speech(input_string):
audio = generate(
text=input_string,
voice=""VOIX"",
model=""MODELE""
)
save(audio, ""001.wav"")
print(""done"")
if __name__ == ""__main__"":
input_string = ""HERE""
tts = UnleashedTTS(nb_accounts=1, create_accounts_threads=0)
text_to_speech(input_string)
";
string textToSpeak = $"{discussion.Messages.Last().contenu}";
if (textToSpeak.Contains(")"))
textToSpeak = textToSpeak.Split(')')[1].Trim();
string py_content = backup.Replace("HERE", textToSpeak);
py_content = py_content.Replace("VOIX", discussion.Messages.Last().auteur.voix.narrateur);
py_content = py_content.Replace("MODELE", discussion.Messages.Last().auteur.voix.modèle);
string py_name = @"C:\Users\Shadow\Documents\eleveb\src\elevenlabs_unleashed\" + "main" + py_content.GetHashCode().ToString() + ".py";
File.WriteAllText(py_name, py_content);
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "\"C:\\Users\\Shadow\\AppData\\Local\\Programs\\Python\\Python311\\python.exe\"",
Arguments = $"{py_name}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
Process process = new Process { StartInfo = startInfo };
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if(error != "")
{
var xeno = 1337;
}
if (File.Exists(@"001.wav"))
{
File.Copy(@"001.wav", $"audios/{idFile}.wav");
File.Delete(@"001.wav");
return true;
}
else
return false;
}
}
}
}