@jambonz/speech-utils 0.0.1
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/.eslintignore +1 -0
- package/.eslintrc.json +126 -0
- package/.github/workflows/ci.yml +27 -0
- package/.github/workflows/publish.yml +23 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/build_stubs.sh +11 -0
- package/config/test.json +13 -0
- package/index.js +32 -0
- package/lib/get-ibm-access-token.js +48 -0
- package/lib/get-nuance-access-token.js +49 -0
- package/lib/get-tts-voices.js +111 -0
- package/lib/purge-tts-cache.js +46 -0
- package/lib/synth-audio.js +469 -0
- package/lib/utils.js +115 -0
- package/package.json +48 -0
- package/protos/nuance/synthesizer.proto +332 -0
- package/protos/riva/proto/riva_audio.proto +36 -0
- package/protos/riva/proto/riva_tts.proto +77 -0
- package/stubs/nuance/synthesizer_grpc_pb.js +104 -0
- package/stubs/nuance/synthesizer_pb.js +6815 -0
- package/stubs/riva/proto/riva_audio_grpc_pb.js +1 -0
- package/stubs/riva/proto/riva_audio_pb.js +31 -0
- package/stubs/riva/proto/riva_tts_grpc_pb.js +99 -0
- package/stubs/riva/proto/riva_tts_pb.js +1278 -0
- package/test/docker-compose-testbed.yaml +39 -0
- package/test/docker_start.js +12 -0
- package/test/docker_stop.js +12 -0
- package/test/ibm.js +78 -0
- package/test/index.js +5 -0
- package/test/nuance.js +50 -0
- package/test/synth.js +431 -0
- package/test/tmp/redis.conf +2054 -0
- package/test/webhook/Dockerfile +23 -0
- package/test/webhook/app.js +125 -0
- package/test/webhook/package-lock.json +1045 -0
- package/test/webhook/package.json +15 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
FROM --platform=linux/amd64 node:18.6.0-alpine as base
|
|
2
|
+
|
|
3
|
+
RUN apk --update --no-cache add --virtual .builds-deps build-base python3
|
|
4
|
+
|
|
5
|
+
WORKDIR /opt/app/
|
|
6
|
+
|
|
7
|
+
FROM base as build
|
|
8
|
+
|
|
9
|
+
COPY package.json package-lock.json ./
|
|
10
|
+
|
|
11
|
+
RUN npm ci
|
|
12
|
+
|
|
13
|
+
COPY . .
|
|
14
|
+
|
|
15
|
+
FROM base
|
|
16
|
+
|
|
17
|
+
COPY --from=build /opt/app /opt/app/
|
|
18
|
+
|
|
19
|
+
ARG NODE_ENV
|
|
20
|
+
|
|
21
|
+
ENV NODE_ENV $NODE_ENV
|
|
22
|
+
|
|
23
|
+
CMD [ "node", "app.js" ]
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const app = express();
|
|
3
|
+
const Websocket = require('ws');
|
|
4
|
+
const listenPort = process.env.HTTP_PORT || 3000;
|
|
5
|
+
let hook_mapping = new Map();
|
|
6
|
+
let ws_packet_count = new Map();
|
|
7
|
+
let ws_metadata = new Map();
|
|
8
|
+
|
|
9
|
+
/** websocket server for listen audio */
|
|
10
|
+
const recvAudio = (socket, req) => {
|
|
11
|
+
let packets = 0;
|
|
12
|
+
let path = req.url;
|
|
13
|
+
console.log('received websocket connection');
|
|
14
|
+
socket.on('message', (data, isBinary) => {
|
|
15
|
+
if (!isBinary) {
|
|
16
|
+
try {
|
|
17
|
+
const msg = JSON.parse(data);
|
|
18
|
+
console.log({msg}, 'received websocket message');
|
|
19
|
+
ws_metadata.set(path, msg);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.log({err}, 'error parsing websocket message');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
packets += data.length;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
socket.on('error', (err) => {
|
|
30
|
+
console.log({err}, 'listen websocket: error');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
socket.on('close', () => {
|
|
34
|
+
ws_packet_count.set(path, packets);
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const wsServer = new Websocket.Server({ noServer: true });
|
|
39
|
+
wsServer.setMaxListeners(0);
|
|
40
|
+
wsServer.on('connection', recvAudio.bind(null));
|
|
41
|
+
|
|
42
|
+
const server = app.listen(listenPort, () => {
|
|
43
|
+
console.log(`sample jambones app server listening on ${listenPort}`);
|
|
44
|
+
});
|
|
45
|
+
server.on('upgrade', (request, socket, head) => {
|
|
46
|
+
console.log('received upgrade request');
|
|
47
|
+
wsServer.handleUpgrade(request, socket, head, (socket) => {
|
|
48
|
+
wsServer.emit('connection', socket, request);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
app.use(express.urlencoded({ extended: true }));
|
|
53
|
+
app.use(express.json());
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Markup language
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
app.all('/:key', (req, res) => {
|
|
60
|
+
let key = req.params.key;
|
|
61
|
+
console.log(req.body, 'POST /' + key);
|
|
62
|
+
addRequestToMap(key, req, hook_mapping);
|
|
63
|
+
return res.json({"audio":"content"})
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Fetch Requests
|
|
67
|
+
app.get('/requests/:key', (req, res) => {
|
|
68
|
+
let key = req.params.key;
|
|
69
|
+
if (hook_mapping.has(key)) {
|
|
70
|
+
return res.json(hook_mapping.get(key));
|
|
71
|
+
} else {
|
|
72
|
+
return res.sendStatus(404);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
app.get('/lastRequest/:key', (req, res) => {
|
|
78
|
+
let key = req.params.key;
|
|
79
|
+
if (hook_mapping.has(key)) {
|
|
80
|
+
let requests = hook_mapping.get(key);
|
|
81
|
+
return res.json(requests[requests.length - 1]);
|
|
82
|
+
} else {
|
|
83
|
+
return res.sendStatus(404);
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// WS Fetch
|
|
88
|
+
app.get('/ws_packet_count/:key', (req, res) => {
|
|
89
|
+
let key = `/${req.params.key}`;
|
|
90
|
+
console.log(key, ws_packet_count);
|
|
91
|
+
if (ws_packet_count.has(key)) {
|
|
92
|
+
return res.json({ count: ws_packet_count.get(key) });
|
|
93
|
+
} else {
|
|
94
|
+
return res.sendStatus(404);
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
app.get('/ws_metadata/:key', (req, res) => {
|
|
99
|
+
let key = `/${req.params.key}`;
|
|
100
|
+
console.log(key, ws_packet_count);
|
|
101
|
+
if (ws_metadata.has(key)) {
|
|
102
|
+
return res.json({ metadata: ws_metadata.get(key) });
|
|
103
|
+
} else {
|
|
104
|
+
return res.sendStatus(404);
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
function addRequestToMap(key, req, map) {
|
|
109
|
+
let headers = new Map()
|
|
110
|
+
for(let i = 0; i < req.rawHeaders.length; i++) {
|
|
111
|
+
if (i % 2 === 0) {
|
|
112
|
+
headers.set(req.rawHeaders[i], req.rawHeaders[i + 1])
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let request = {
|
|
116
|
+
'url': req.url,
|
|
117
|
+
'headers': Object.fromEntries(headers),
|
|
118
|
+
'body': req.body
|
|
119
|
+
}
|
|
120
|
+
if (map.has(key)) {
|
|
121
|
+
map.get(key).push(request);
|
|
122
|
+
} else {
|
|
123
|
+
map.set(key, [request]);
|
|
124
|
+
}
|
|
125
|
+
}
|