sip-lab 1.23.0 → 1.24.0

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.
@@ -0,0 +1,34 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 2015 Alpha Cephei Inc. All rights
3
+ * reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ *
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ *
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in
14
+ * the documentation and/or other materials provided with the
15
+ * distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY ALPHA CEPHEI INC. ``AS IS'' AND.
18
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,.
19
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALPHA CEPHEI INC.
21
+ * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT.
23
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,.
24
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY.
25
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT.
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE.
27
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *
29
+ * ====================================================================
30
+ *
31
+ */
32
+
33
+ This directory contains generic US english acoustic model trained with
34
+ latest sphinxtrain.
@@ -0,0 +1,12 @@
1
+ -lowerf 130
2
+ -upperf 6800
3
+ -nfilt 25
4
+ -transform dct
5
+ -lifter 22
6
+ -feat 1s_c_d_dd
7
+ -svspec 0-12/13-25/26-38
8
+ -agc none
9
+ -cmn batch
10
+ -varnorm no
11
+ -model ptm
12
+ -remove_noise yes
@@ -0,0 +1,5 @@
1
+ <s> SIL
2
+ </s> SIL
3
+ <sil> SIL
4
+ [NOISE] +NSN+
5
+ [SPEECH] +SPN+
Binary file
@@ -0,0 +1,182 @@
1
+ var sip = require ('../index.js')
2
+ var Zeq = require('@mayama/zeq')
3
+ var z = new Zeq()
4
+ var m = require('data-matching')
5
+ var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
7
+
8
+ async function test() {
9
+ //sip.set_log_level(6)
10
+ sip.dtmf_aggregation_on(500)
11
+
12
+ sip.set_codecs("pcmu/8000/1:128")
13
+
14
+ z.trap_events(sip.event_source, 'event', (evt) => {
15
+ var e = evt.args[0]
16
+ return e
17
+ })
18
+
19
+ console.log(sip.start((data) => { console.log(data)} ))
20
+
21
+ t1 = sip.transport.create({address: "127.0.0.1", type: 'tcp'})
22
+ t2 = sip.transport.create({address: "127.0.0.1", type: 'tcp'})
23
+
24
+ console.log("t1", t1)
25
+ console.log("t2", t2)
26
+
27
+ oc = sip.call.create(t1.id, {
28
+ from_uri: '"abc"<sip:alice@test.com>',
29
+ to_uri: `sip:bob@${t2.address}:${t2.port}`,
30
+ headers: {
31
+ 'X-MyHeader1': 'abc',
32
+ 'X-MyHeader2': 'def',
33
+ },
34
+ })
35
+
36
+ await z.wait([
37
+ {
38
+ event: "incoming_call",
39
+ call_id: m.collect("call_id"),
40
+ msg: sip_msg({
41
+ $rm: 'INVITE',
42
+ $fU: 'alice',
43
+ $fd: 'test.com',
44
+ $tU: 'bob',
45
+ '$hdr(X-MyHeader1)': 'abc',
46
+ 'hdr_x_myheader2': 'def',
47
+ }),
48
+ },
49
+ {
50
+ event: 'response',
51
+ call_id: oc.id,
52
+ method: 'INVITE',
53
+ msg: sip_msg({
54
+ $rs: '100',
55
+ $rr: 'Trying',
56
+ '$(hdrcnt(via))': 1,
57
+ 'hdr_call_id': m.collect('sip_call_id'),
58
+ $fU: 'alice',
59
+ $fd: 'test.com',
60
+ $tU: 'bob',
61
+ '$hdr(l)': '0',
62
+ }),
63
+ },
64
+ ], 1000)
65
+
66
+ ic = {
67
+ id: z.store.call_id,
68
+ sip_call_id: z.store.sip_call_id,
69
+ }
70
+
71
+ sip.call.respond(ic.id, {
72
+ code: 200,
73
+ reason:'OK',
74
+ headers: {
75
+ 'X-MyHeader3': 'ghi',
76
+ 'X-MyHeader4': 'jkl',
77
+ },
78
+ })
79
+
80
+ await z.wait([
81
+ {
82
+ event: 'media_update',
83
+ call_id: oc.id,
84
+ status: 'ok',
85
+ },
86
+ {
87
+ event: 'media_update',
88
+ call_id: ic.id,
89
+ status: 'ok',
90
+ },
91
+ {
92
+ event: 'response',
93
+ call_id: oc.id,
94
+ method: 'INVITE',
95
+ msg: sip_msg({
96
+ $rs: '200',
97
+ $rr: 'OK',
98
+ '$(hdrcnt(v))': 1,
99
+ $fU: 'alice',
100
+ $fd: 'test.com',
101
+ $tU: 'bob',
102
+ '$hdr(content-type)': 'application/sdp',
103
+ $rb: '!{_}a=sendrecv',
104
+ '$hdr(X-MyHeader3)': 'ghi',
105
+ '$hdr(X-MyHeader4)': 'jkl',
106
+ }),
107
+ },
108
+ ], 1000)
109
+
110
+ await z.sleep(100)
111
+
112
+ sip.call.start_record_wav(oc.id, {file: './oc.wav'})
113
+ sip.call.start_record_wav(ic.id, {file: './ic.wav'})
114
+
115
+ sip.call.start_speech_recog(oc.id)
116
+ sip.call.start_speech_recog(ic.id)
117
+
118
+ await z.sleep(100)
119
+
120
+ sip.call.start_play_wav(oc.id, {file: 'samples/artifacts/hello_good_morning.wav', end_of_file_event: true, no_loop: true})
121
+ sip.call.start_play_wav(ic.id, {file: 'samples/artifacts/hello_good_morning.wav', end_of_file_event: true, no_loop: true})
122
+
123
+ await z.wait([
124
+ {
125
+ event: 'end_of_file',
126
+ call_id: ic.id,
127
+ },
128
+ {
129
+ event: 'end_of_file',
130
+ call_id: oc.id,
131
+ },
132
+ {
133
+ event: 'speech_transcript',
134
+ call_id: oc.id,
135
+ //transcript: 'hello good morning', // bad transcript (will not match)
136
+ },
137
+ {
138
+ event: 'speech_transcript',
139
+ call_id: ic.id,
140
+ //transcript: 'hello good morning', // bad transcript (will not match)
141
+ },
142
+ ], 4000)
143
+
144
+ sip.call.stop_record_wav(oc.id)
145
+ sip.call.stop_record_wav(ic.id)
146
+
147
+ sip.call.terminate(oc.id)
148
+
149
+ await z.wait([
150
+ {
151
+ event: 'call_ended',
152
+ call_id: oc.id,
153
+ },
154
+ {
155
+ event: 'call_ended',
156
+ call_id: ic.id,
157
+ },
158
+ {
159
+ event: 'response',
160
+ call_id: oc.id,
161
+ method: 'BYE',
162
+ msg: sip_msg({
163
+ $rs: '200',
164
+ $rr: 'OK',
165
+ }),
166
+ },
167
+ ], 1000)
168
+
169
+ await z.sleep(100)
170
+
171
+ console.log("Success")
172
+
173
+ sip.stop()
174
+ }
175
+
176
+
177
+ test()
178
+ .catch(e => {
179
+ console.error(e)
180
+ process.exit(1)
181
+ })
182
+
@@ -0,0 +1,186 @@
1
+ var sip = require ('../index.js')
2
+ var Zeq = require('@mayama/zeq')
3
+ var z = new Zeq()
4
+ var m = require('data-matching')
5
+ var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
7
+
8
+ async function test() {
9
+ //sip.set_log_level(6)
10
+ sip.dtmf_aggregation_on(500)
11
+
12
+ sip.set_codecs("speex/16000/1:128")
13
+
14
+ z.trap_events(sip.event_source, 'event', (evt) => {
15
+ var e = evt.args[0]
16
+ return e
17
+ })
18
+
19
+ console.log(sip.start((data) => { console.log(data)} ))
20
+
21
+ t1 = sip.transport.create({address: "127.0.0.1", type: 'tcp'})
22
+ t2 = sip.transport.create({address: "127.0.0.1", type: 'tcp'})
23
+
24
+ console.log("t1", t1)
25
+ console.log("t2", t2)
26
+
27
+ oc = sip.call.create(t1.id, {
28
+ from_uri: '"abc"<sip:alice@test.com>',
29
+ to_uri: `sip:bob@${t2.address}:${t2.port}`,
30
+ headers: {
31
+ 'X-MyHeader1': 'abc',
32
+ 'X-MyHeader2': 'def',
33
+ },
34
+ })
35
+
36
+ await z.wait([
37
+ {
38
+ event: "incoming_call",
39
+ call_id: m.collect("call_id"),
40
+ msg: sip_msg({
41
+ $rm: 'INVITE',
42
+ $fU: 'alice',
43
+ $fd: 'test.com',
44
+ $tU: 'bob',
45
+ '$hdr(X-MyHeader1)': 'abc',
46
+ 'hdr_x_myheader2': 'def',
47
+ }),
48
+ },
49
+ {
50
+ event: 'response',
51
+ call_id: oc.id,
52
+ method: 'INVITE',
53
+ msg: sip_msg({
54
+ $rs: '100',
55
+ $rr: 'Trying',
56
+ '$(hdrcnt(via))': 1,
57
+ 'hdr_call_id': m.collect('sip_call_id'),
58
+ $fU: 'alice',
59
+ $fd: 'test.com',
60
+ $tU: 'bob',
61
+ '$hdr(l)': '0',
62
+ }),
63
+ },
64
+ ], 1000)
65
+
66
+ ic = {
67
+ id: z.store.call_id,
68
+ sip_call_id: z.store.sip_call_id,
69
+ }
70
+
71
+ sip.call.respond(ic.id, {
72
+ code: 200,
73
+ reason:'OK',
74
+ headers: {
75
+ 'X-MyHeader3': 'ghi',
76
+ 'X-MyHeader4': 'jkl',
77
+ },
78
+ })
79
+
80
+ await z.wait([
81
+ {
82
+ event: 'media_update',
83
+ call_id: oc.id,
84
+ status: 'ok',
85
+ },
86
+ {
87
+ event: 'media_update',
88
+ call_id: ic.id,
89
+ status: 'ok',
90
+ },
91
+ {
92
+ event: 'response',
93
+ call_id: oc.id,
94
+ method: 'INVITE',
95
+ msg: sip_msg({
96
+ $rs: '200',
97
+ $rr: 'OK',
98
+ '$(hdrcnt(v))': 1,
99
+ $fU: 'alice',
100
+ $fd: 'test.com',
101
+ $tU: 'bob',
102
+ '$hdr(content-type)': 'application/sdp',
103
+ $rb: '!{_}a=sendrecv',
104
+ '$hdr(X-MyHeader3)': 'ghi',
105
+ '$hdr(X-MyHeader4)': 'jkl',
106
+ }),
107
+ },
108
+ ], 1000)
109
+
110
+ await z.sleep(100)
111
+
112
+ sip.call.start_record_wav(oc.id, {file: './oc.wav'})
113
+ sip.call.start_record_wav(ic.id, {file: './ic.wav'})
114
+
115
+ sip.call.start_speech_recog(oc.id)
116
+ sip.call.start_speech_recog(ic.id)
117
+
118
+ await z.sleep(100)
119
+
120
+ sip.call.start_speech_synth(oc.id, {voice: 'kal16', text: 'Good morning.', end_of_speech_event: true, no_loop: true})
121
+ sip.call.start_speech_synth(ic.id, {voice: 'kal16', text: 'How are you?', end_of_speech_event: true, no_loop: true})
122
+
123
+ await z.wait([
124
+ {
125
+ event: 'end_of_speech',
126
+ call_id: ic.id,
127
+ },
128
+ {
129
+ event: 'end_of_speech',
130
+ call_id: oc.id,
131
+ },
132
+ {
133
+ event: 'speech_transcript',
134
+ call_id: oc.id,
135
+ transcript: 'how are you',
136
+ },
137
+ {
138
+ event: 'speech_transcript',
139
+ call_id: ic.id,
140
+ transcript: 'good morning',
141
+ },
142
+ ], 3000)
143
+
144
+ sip.call.stop_speech_synth(oc.id) // this is not actually necessary. It is used just to confirm the command works
145
+ sip.call.stop_speech_synth(ic.id) // this is not actually necessary. It is used just to confirm the command works
146
+
147
+
148
+ sip.call.stop_record_wav(oc.id)
149
+ sip.call.stop_record_wav(ic.id)
150
+
151
+ sip.call.terminate(oc.id)
152
+
153
+ await z.wait([
154
+ {
155
+ event: 'call_ended',
156
+ call_id: oc.id,
157
+ },
158
+ {
159
+ event: 'call_ended',
160
+ call_id: ic.id,
161
+ },
162
+ {
163
+ event: 'response',
164
+ call_id: oc.id,
165
+ method: 'BYE',
166
+ msg: sip_msg({
167
+ $rs: '200',
168
+ $rr: 'OK',
169
+ }),
170
+ },
171
+ ], 1000)
172
+
173
+ await z.sleep(100)
174
+
175
+ console.log("Success")
176
+
177
+ sip.stop()
178
+ }
179
+
180
+
181
+ test()
182
+ .catch(e => {
183
+ console.error(e)
184
+ process.exit(1)
185
+ })
186
+
@@ -126,7 +126,6 @@ async function test() {
126
126
  },
127
127
  ], 2000)
128
128
 
129
-
130
129
  sip.call.reinvite(oc.id)
131
130
 
132
131
  await z.wait([
@@ -339,6 +338,50 @@ async function test() {
339
338
 
340
339
  await z.sleep(2000)
341
340
 
341
+ sip.call.reinvite(oc.id)
342
+
343
+ await z.wait([
344
+ {
345
+ event: 'reinvite',
346
+ call_id: ic.id
347
+ },
348
+ ], 1000)
349
+
350
+ sip.call.respond(ic.id, {code: 200, reason: 'OK'})
351
+
352
+ await z.wait([
353
+ {
354
+ event: 'response',
355
+ call_id: oc.id,
356
+ method: 'INVITE',
357
+ msg: sip_msg({
358
+ $rs: '100',
359
+ }),
360
+ },
361
+ {
362
+ event: 'response',
363
+ call_id: oc.id,
364
+ method: 'INVITE',
365
+ msg: sip_msg({
366
+ $rs: '200',
367
+ $rr: 'OK',
368
+ $rb: '!{_}a=sendrecv',
369
+ }),
370
+ },
371
+ {
372
+ event: 'media_update',
373
+ call_id: oc.id,
374
+ status: 'ok',
375
+ },
376
+ {
377
+ event: 'media_update',
378
+ call_id: ic.id,
379
+ status: 'ok',
380
+ },
381
+ ], 500)
382
+
383
+ await z.sleep(2000)
384
+
342
385
  stat1 = sip.call.get_stream_stat(oc.id, {media_id: 0})
343
386
  stat2 = sip.call.get_stream_stat(ic.id, {media_id: 0})
344
387
 
package/src/addon.cpp CHANGED
@@ -603,6 +603,41 @@ Napi::Value call_start_speech_synth(const Napi::CallbackInfo &info) {
603
603
  return env.Null();
604
604
  }
605
605
 
606
+ Napi::Value call_start_speech_recog(const Napi::CallbackInfo &info) {
607
+ Napi::Env env = info.Env();
608
+
609
+ if (info.Length() != 2) {
610
+ Napi::Error::New(env,
611
+ "Wrong number of arguments. Expected: call_id, params.")
612
+ .ThrowAsJavaScriptException();
613
+ return env.Null();
614
+ }
615
+
616
+ if (!info[0].IsNumber()) {
617
+ Napi::TypeError::New(env, "call_id must be number.")
618
+ .ThrowAsJavaScriptException();
619
+ return env.Null();
620
+ }
621
+ int call_id = info[0].As<Napi::Number>().Int32Value();
622
+
623
+ if (!info[1].IsString()) {
624
+ Napi::TypeError::New(env, "params must be a JSON string.")
625
+ .ThrowAsJavaScriptException();
626
+ return env.Null();
627
+ }
628
+ const string json = info[1].As<Napi::String>().Utf8Value();
629
+
630
+ int res = pjw_call_start_speech_recog(call_id, json.c_str());
631
+
632
+ if (res != 0) {
633
+ Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
634
+ return env.Null();
635
+ }
636
+
637
+ return env.Null();
638
+ }
639
+
640
+
606
641
  Napi::Value call_stop_record_wav(const Napi::CallbackInfo &info) {
607
642
  Napi::Env env = info.Env();
608
643
 
@@ -1336,6 +1371,8 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
1336
1371
 
1337
1372
  exports.Set("call_start_speech_synth", Napi::Function::New(env, call_start_speech_synth));
1338
1373
 
1374
+ exports.Set("call_start_speech_recog", Napi::Function::New(env, call_start_speech_recog));
1375
+
1339
1376
  exports.Set("call_stop_record_wav",
1340
1377
  Napi::Function::New(env, call_stop_record_wav));
1341
1378
  exports.Set("call_stop_play_wav",
@@ -111,6 +111,12 @@ int make_evt_end_of_speech(char *dest, int size, long call_id) {
111
111
  "{\"event\": \"end_of_speech\", \"call_id\": %ld}", call_id);
112
112
  }
113
113
 
114
+ int make_evt_speech_transcript(char *dest, int size, long call_id, char* transcript) {
115
+ return snprintf(
116
+ dest, size,
117
+ "{\"event\": \"speech_transcript\", \"call_id\": %ld, \"transcript\": \"%s\"}", call_id, transcript);
118
+ }
119
+
114
120
  int make_evt_tcp_msg(char *dest, int size, long call_id, const char *protocol, char *data, int data_len) {
115
121
  return snprintf(
116
122
  dest, size,
@@ -38,6 +38,8 @@ int make_evt_end_of_file(char *dest, int size, long call_id);
38
38
 
39
39
  int make_evt_end_of_speech(char *dest, int size, long call_id);
40
40
 
41
+ int make_evt_speech_transcript(char *dest, int size, long call_id, char* transcript);
42
+
41
43
  int make_evt_tcp_msg(char *dest, int size, long call_id, const char *protocol, char *data, int data_len);
42
44
 
43
45
  #endif
@@ -0,0 +1,19 @@
1
+ #ifndef __POCKETSPHINX_PORT_H__
2
+ #define __POCKETSPHINX_PORT_H__
3
+
4
+ #include <pjmedia/port.h>
5
+
6
+ PJ_BEGIN_DECL
7
+
8
+ PJ_DEF(pj_status_t) pjmedia_pocketsphinx_port_create( pj_pool_t *pool,
9
+ unsigned clock_rate,
10
+ unsigned channel_count,
11
+ unsigned samples_per_frame,
12
+ unsigned bits_per_sample,
13
+ void (*cb)(pjmedia_port*, void *user_data, char *transcript),
14
+ void *cb_user_data,
15
+ pjmedia_port **p_port);
16
+
17
+ PJ_END_DECL
18
+
19
+ #endif /* __POCKETSPHINX_PORT_H__ */
@@ -143,10 +143,7 @@ PJ_DEF(pj_status_t) pjmedia_flite_port_create( pj_pool_t *pool,
143
143
  if (!strcasecmp(voice, "awb")) {
144
144
  flite->v = globals.awb;
145
145
  } else if (!strcasecmp(voice, "kal")) {
146
- /* "kal" is 8kHz and the native rate is set to 16kHz
147
- * so kal talks a little bit too fast ...
148
- * for now: "symlink" kal to kal16
149
- */ flite->v = globals.kal16;
146
+ flite->v = globals.kal; // this uses SamplingRate of 8000. All others use 16000
150
147
  } else if (!strcasecmp(voice, "rms")) {
151
148
  flite->v = globals.rms;
152
149
  } else if (!strcasecmp(voice, "slt")) {
@@ -194,12 +191,12 @@ static pj_status_t flite_get_frame(pjmedia_port *port,
194
191
  struct flite_t *flite = (struct flite_t*)port;
195
192
 
196
193
  if(!flite->w) {
197
- printf("flite no data\n");
194
+ //printf("flite no data\n");
198
195
  frame->type = PJMEDIA_FRAME_TYPE_NONE;
199
196
  return PJ_SUCCESS;
200
197
  }
201
198
 
202
- printf("written_samples=%i num_samples=%i\n", flite->written_samples, flite->w->num_samples);
199
+ //printf("written_samples=%i num_samples=%i\n", flite->written_samples, flite->w->num_samples);
203
200
  if (flite->written_samples + PJMEDIA_PIA_SPF(&port->info) > (unsigned)flite->w->num_samples) {
204
201
  printf("flite end of speech\n");
205
202
 
@@ -235,7 +232,7 @@ static pj_status_t flite_get_frame(pjmedia_port *port,
235
232
  memcpy(frame->buf, flite->w->samples + flite->written_samples, PJMEDIA_PIA_SPF(&port->info)*2);
236
233
  flite->written_samples += PJMEDIA_PIA_SPF(&port->info);
237
234
  frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
238
- printf("flite data written samples=%i\n", PJMEDIA_PIA_SPF(&port->info));
235
+ //printf("flite data written samples=%i\n", PJMEDIA_PIA_SPF(&port->info));
239
236
 
240
237
  return PJ_SUCCESS;
241
238
  }