forked from abeiro/HerikaServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvsx.php
executable file
·147 lines (106 loc) · 3.73 KB
/
vsx.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
require_once("lib/utils.php");
/* Voice Sample Extractor */
$path = dirname((__FILE__)) . DIRECTORY_SEPARATOR;
require_once($path . "conf".DIRECTORY_SEPARATOR."conf.php"); // API KEY must be there
require_once($path . "lib" .DIRECTORY_SEPARATOR."{$GLOBALS["DBDRIVER"]}.class.php");
require_once($path . "lib".DIRECTORY_SEPARATOR."fuz_convert.php"); // API KEY must be there
require_once($path . "lib" .DIRECTORY_SEPARATOR."auditing.php");
// Put info into DB asap
$db=new sql();
$voicelogic = $GLOBALS["TTS"]["XTTSFASTAPI"]["voicelogic"];
if ($voicelogic === 'voicetype') {
//db insert for name entry for data_functions.
$codename = npcNameToCodename($_GET["codename"]);
$db->delete("conf_opts", "id='" . $db->escape("Nametype/$codename") . "'");
$db->insert(
'conf_opts',
array(
'id' => $db->escape("Nametype/$codename"),
'value' => $_GET["oname"]
)
);
// new logic so codename is set to voicetype so it generates voicetype sample
$voicetype = explode("\\", $_GET["oname"]); // Split the path
$codename = strtolower($voicetype[3]); // Use the 4th part of the path
// Delete and insert the database entry
$db->delete("conf_opts", "id='" . $db->escape("Voicetype/$codename") . "'");
$db->insert(
'conf_opts',
array(
'id' => $db->escape("Voicetype/$codename"),
'value' => $_GET["oname"]
)
);
$db->close();
} else {
$codename = npcNameToCodename($_GET["codename"]);
// Old name logic
$db->delete("conf_opts", "id='" . $db->escape("Voicetype/$codename") . "'");
$db->insert(
'conf_opts',
array(
'id' => $db->escape("Voicetype/$codename"),
'value' => $_GET["oname"]
)
);
$db->close();
}
if (strpos($_GET["oname"],".fuz")) {
$ext="fuz";
} else if (strpos($_GET["oname"],".xwm")) {
$ext="xwm";
} else if (strpos($_GET["oname"],".wav")) {
$ext="wav";
}
$already=file_exists("{$GLOBALS["TTS"]["XTTSFASTAPI"]["endpoint"]}/sample/$codename.wav");
$finalName=__DIR__.DIRECTORY_SEPARATOR."soundcache/_vsx_".md5($_FILES["file"]["tmp_name"]).".$ext";
@copy($_FILES["file"]["tmp_name"] ,$finalName);
if (!$already) {
if (file_exists($path."data/voices/$codename.wav")) {
// File exists in HS data/voices. Dont't convert again
$finalFile=$path."data/voices/$codename.wav";
} else {
if (!$_FILES["file"]["tmp_name"])
die("VSX error, no data given");
if (filesize($_FILES["file"]["tmp_name"])==0) {
error_log("Empty file {$_FILES["file"]["tmp_name"]}");
die();
}
error_log("Received sample: {$_GET["oname"]}");
if (strpos($_GET["oname"],".fuz")) {
$finalFile=fuzToWav($finalName);
} else if (strpos($_GET["oname"],".xwm")) {
$finalFile=xwmToWav($finalName);
} else if (strpos($_GET["oname"],".wav")) {
$finalFile=wavToWav($finalName);
}
}
if (!isset($GLOBALS["TTS"]["XTTSFASTAPI"]["endpoint"]) || !($GLOBALS["TTS"]["XTTSFASTAPI"]["endpoint"]) ) {
die("Error");
}
} else {
error_log("Empty file {$_FILES["file"]["tmp_name"]} already exists at {$GLOBALS["TTS"]["XTTSFASTAPI"]["endpoint"]}/sample/$codename.wav");
}
if ($already) {
die();
}
// Lets store voice files
@copy($finalFile,$path."data/voices/$codename.wav");
$url = $GLOBALS["TTS"]["XTTSFASTAPI"]["endpoint"].'/upload_sample';
$curl = curl_init();
// Set cURL options
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array(
'wavFile' => new CURLFile($finalFile, 'audio/wav', "$codename.wav")
),
CURLOPT_HTTPHEADER => array(
'Content-Type: multipart/form-data'
)
));
// Execute cURL request and get response
$response = curl_exec($curl);
?>