agentgui 1.0.170 → 1.0.171
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/speech.js +44 -4
- package/package.json +1 -1
package/lib/speech.js
CHANGED
|
@@ -8,9 +8,19 @@ const require = createRequire(import.meta.url);
|
|
|
8
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
const ROOT = path.dirname(__dirname);
|
|
10
10
|
const DATA_DIR = path.join(ROOT, 'data');
|
|
11
|
-
const VOICES_DIR = path.join(ROOT, 'voices');
|
|
12
|
-
const HOME_VOICES_DIR = path.join(os.homedir(), 'voices');
|
|
13
11
|
const AUDIO_EXTENSIONS = ['.mp3', '.wav', '.ogg', '.flac', '.m4a'];
|
|
12
|
+
|
|
13
|
+
function getVoiceDirs() {
|
|
14
|
+
const dirs = [];
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
const add = (d) => { const r = path.resolve(d); if (!seen.has(r)) { seen.add(r); dirs.push(r); } };
|
|
17
|
+
const startupCwd = process.env.STARTUP_CWD || process.cwd();
|
|
18
|
+
add(path.join(startupCwd, 'voices'));
|
|
19
|
+
add(path.join(ROOT, 'voices'));
|
|
20
|
+
add(path.join(os.homedir(), 'voices'));
|
|
21
|
+
return dirs;
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
const MIN_WAV_SIZE = 1000;
|
|
15
25
|
|
|
16
26
|
const BASE_VOICES = [
|
|
@@ -24,6 +34,24 @@ const BASE_VOICES = [
|
|
|
24
34
|
{ id: 'ksp', name: 'KSP', gender: 'male', accent: 'Indian' },
|
|
25
35
|
];
|
|
26
36
|
|
|
37
|
+
async function convertToWav(filePath) {
|
|
38
|
+
const wavPath = filePath.replace(/\.[^.]+$/, '.wav');
|
|
39
|
+
if (fs.existsSync(wavPath)) return wavPath;
|
|
40
|
+
try {
|
|
41
|
+
console.log('[VOICES] Converting to WAV:', filePath);
|
|
42
|
+
const audio = await decodeAudioFile(filePath);
|
|
43
|
+
const wav = encodeWav(audio, SAMPLE_RATE_STT);
|
|
44
|
+
fs.writeFileSync(wavPath, wav);
|
|
45
|
+
console.log('[VOICES] Converted:', path.basename(wavPath));
|
|
46
|
+
return wavPath;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error('[VOICES] Conversion failed for', filePath + ':', err.message);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const pendingConversions = new Map();
|
|
54
|
+
|
|
27
55
|
function scanVoiceDir(dir) {
|
|
28
56
|
const voices = [];
|
|
29
57
|
try {
|
|
@@ -32,6 +60,18 @@ function scanVoiceDir(dir) {
|
|
|
32
60
|
const ext = path.extname(file).toLowerCase();
|
|
33
61
|
if (!AUDIO_EXTENSIONS.includes(ext)) continue;
|
|
34
62
|
const baseName = path.basename(file, ext);
|
|
63
|
+
if (ext !== '.wav') {
|
|
64
|
+
const wavFile = baseName + '.wav';
|
|
65
|
+
if (fs.existsSync(path.join(dir, wavFile))) continue;
|
|
66
|
+
const fullPath = path.join(dir, file);
|
|
67
|
+
if (!pendingConversions.has(fullPath)) {
|
|
68
|
+
pendingConversions.set(fullPath, convertToWav(fullPath).then(result => {
|
|
69
|
+
pendingConversions.delete(fullPath);
|
|
70
|
+
return result;
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
35
75
|
const id = 'custom_' + baseName.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
36
76
|
const name = baseName.replace(/_/g, ' ');
|
|
37
77
|
voices.push({ id, name, gender: 'custom', accent: 'custom', isCustom: true, sourceDir: dir });
|
|
@@ -45,7 +85,7 @@ function scanVoiceDir(dir) {
|
|
|
45
85
|
function loadCustomVoices() {
|
|
46
86
|
const seen = new Set();
|
|
47
87
|
const voices = [];
|
|
48
|
-
for (const dir of
|
|
88
|
+
for (const dir of getVoiceDirs()) {
|
|
49
89
|
for (const v of scanVoiceDir(dir)) {
|
|
50
90
|
if (seen.has(v.id)) continue;
|
|
51
91
|
seen.add(v.id);
|
|
@@ -170,7 +210,7 @@ async function getSpeakerEmbeddingPipeline() {
|
|
|
170
210
|
|
|
171
211
|
function findCustomVoiceFile(voiceId) {
|
|
172
212
|
const baseName = voiceId.replace(/^custom_/, '');
|
|
173
|
-
for (const dir of
|
|
213
|
+
for (const dir of getVoiceDirs()) {
|
|
174
214
|
for (const ext of AUDIO_EXTENSIONS) {
|
|
175
215
|
const candidate = path.join(dir, baseName + ext);
|
|
176
216
|
if (fs.existsSync(candidate)) return candidate;
|