forked from watson-developer-cloud/node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv1.ts
101 lines (78 loc) · 2.75 KB
/
v1.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
95
96
97
98
99
100
101
import GeneratedTextToSpeechV1 = require('./v1-generated');
class TextToSpeechV1 extends GeneratedTextToSpeechV1 {
constructor(options) {
super(options);
}
getCustomizations(params, callback) {
return super.listVoiceModels(params, callback);
}
getCustomization(params, callback) {
return super.getVoiceModel(params, callback);
}
updateCustomization(params, callback) {
return super.updateVoiceModel(params, callback);
}
deleteCustomization(params, callback) {
return super.deleteVoiceModel(params, callback);
}
createCustomization(params, callback) {
return super.createVoiceModel(params, callback);
}
getWords(params, callback) {
return super.listWords(params, callback);
}
voices(params, callback) {
return super.listVoices(params, callback);
}
voice(params, callback) {
return super.getVoice(params, callback);
}
pronunciation(params, callback) {
return super.getPronunciation(params, callback);
}
/**
* Repair the WAV header of an audio/wav file.
*
* @param {Buffer} wavFileData - Wave audio - will be edited in place and returned
* @return {Buffer} wavFileData - the original Buffer, with a correct header
*/
repairWavHeader = (wavFileData) => {
const totalBytes = wavFileData.length;
// bytes 4-8 in header give the total file size,
// after the first 8 bytes
// this is a reliable constant
const chunkSize = totalBytes - 8;
wavFileData.writeInt32LE(chunkSize, 4);
// the first subchunk is at byte 12, the fmt subchunk
// this is the only other reliable constant
let chunkIdOffset = 12;
const fieldSize = 4;
// every subchunk has a 4 byte id followed by a 4 byte size field
let chunkSizeOffset = chunkIdOffset + fieldSize;
let subchunk2sizeLocation = 0;
// initialize values to hold data of each chunk we come across
let tempChunkID = '';
let tempChunkSize = 0;
while (tempChunkID !== 'data') {
if (chunkSizeOffset + fieldSize > totalBytes) {
break;
}
tempChunkID = wavFileData
.slice(chunkIdOffset, chunkIdOffset + fieldSize)
.toString('ascii');
tempChunkSize = wavFileData.readInt32LE(chunkSizeOffset);
// save the location of the data size field
if (tempChunkID === 'data') {
subchunk2sizeLocation = chunkSizeOffset;
}
// skip over all the data in the temp chunk
chunkIdOffset = chunkSizeOffset + fieldSize + tempChunkSize;
chunkSizeOffset = chunkIdOffset + fieldSize;
}
const subchunk2size = totalBytes - subchunk2sizeLocation - fieldSize;
// update the size of the audio data and return
wavFileData.writeInt32LE(subchunk2size, subchunk2sizeLocation);
return wavFileData;
};
}
export = TextToSpeechV1;