-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
96 lines (73 loc) · 3.28 KB
/
index.ts
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
import * as waapi from 'waapi-client';
import * as path from 'path';
import * as async from 'async';
import * as os from 'os';
import * as fs from 'fs-extra'
import { ak } from 'waapi';
import {spawn} from 'child_process';
const generateDir = path.join( os.tmpdir(),'waapi-tts');
const speakScriptPath = path.join( path.dirname(process.argv[1]), 'speak.ps1');
async function main() {
try {
// Connect to WAAPI
// Ensure you enabled WAAPI in Wwise's User Preferences.
// Refer to readme.md for more information
var session = await waapi.connect('ws://localhost:8080/waapi');
var wwiseInfo = await session.call(ak.wwise.core.getInfo, {});
console.log(`Connected to ${wwiseInfo.displayName} ${wwiseInfo.version.displayName}!`);
// Obtain information about Wwise
var selection = await session.call(ak.wwise.ui.getSelectedObjects,{},{ return:['id','name','notes','path']});
console.log(`Retrieved ${selection.objects.length} object(s) selected.`);
console.log(`Using '${speakScriptPath}' to generate WAV files.`);
fs.ensureDirSync(generateDir);
var copy : any[] = [];
Object.assign(copy, selection.objects);
async.map(copy, function(item, cb){
const wavFile = path.join(generateDir,item.name) + '.wav';
console.log(`Writing '${wavFile}' with '${item.notes}'.`);
try {
// Use text to speech service in Windows through the powershell
var spawned = spawn('powershell.exe',
[ '-executionpolicy', 'bypass', '-File', speakScriptPath, wavFile, item.notes ]);
spawned.on('close', function (code) {
console.log(`Child closes with code ${code}`);
// Create a import entry
return cb(null, {
audioFile: wavFile,
objectPath: `${item.path}\\<AudioFileSource>${item.name}`
})
});
spawned.on('error', function(error:Error) {
return cb(new Error(`Spawn error: ${error.message}`));
});
} catch (error) {
return cb(new Error(`Cannot launch text to speech command: ${error.message}`));
}
}, async function(err, result: any){
// at the end of the text to speech, import to wwise
var args = {
"importOperation": "useExisting",
"default": {
"importLanguage": "English(US)"
},
"imports": result
};
console.log(JSON.stringify(args,null,4));
// Import with WAAPI
await session.call(ak.wwise.core.audio.import_,args);
// Delete temporary
var audioFiles = result.map(i=>i.audioFile);
await Promise.all(audioFiles.map(i=>fs.unlink(i)));
// Quit
await session.disconnect();
process.exit();
});
}
catch (e) {
console.error(`exception: ${e}`);
console.log('Press any key to exit');
process.stdin.resume();
process.stdin.on('data', process.exit.bind(process, 0));
}
}
main();