mingyang91 commited on
Commit
254fd5f
·
verified ·
1 Parent(s): 786313f

test single channel

Browse files
Files changed (6) hide show
  1. Cargo.lock +120 -23
  2. Cargo.toml +3 -0
  3. src/asr/aws.rs +1 -11
  4. src/asr/mod.rs +12 -0
  5. src/main.rs +124 -1
  6. whisper/samples/samples_jfk.wav +0 -0
Cargo.lock CHANGED
@@ -121,7 +121,7 @@ dependencies = [
121
  "aws-smithy-runtime-api",
122
  "aws-smithy-types",
123
  "aws-types",
124
- "bytes",
125
  "fastrand",
126
  "hex",
127
  "http",
@@ -154,7 +154,7 @@ dependencies = [
154
  "aws-smithy-runtime-api",
155
  "aws-smithy-types",
156
  "aws-types",
157
- "bytes",
158
  "http",
159
  "http-body",
160
  "pin-project-lite",
@@ -200,7 +200,7 @@ dependencies = [
200
  "aws-smithy-runtime-api",
201
  "aws-smithy-types",
202
  "aws-types",
203
- "bytes",
204
  "http",
205
  "regex",
206
  "tracing",
@@ -222,7 +222,7 @@ dependencies = [
222
  "aws-smithy-runtime-api",
223
  "aws-smithy-types",
224
  "aws-types",
225
- "bytes",
226
  "http",
227
  "regex",
228
  "tracing",
@@ -244,7 +244,7 @@ dependencies = [
244
  "aws-smithy-runtime-api",
245
  "aws-smithy-types",
246
  "aws-types",
247
- "bytes",
248
  "http",
249
  "regex",
250
  "tracing",
@@ -291,7 +291,7 @@ dependencies = [
291
  "aws-smithy-runtime-api",
292
  "aws-smithy-types",
293
  "aws-types",
294
- "bytes",
295
  "http",
296
  "hyper",
297
  "regex",
@@ -314,7 +314,7 @@ dependencies = [
314
  "aws-smithy-runtime-api",
315
  "aws-smithy-types",
316
  "aws-types",
317
- "bytes",
318
  "fastrand",
319
  "http",
320
  "regex",
@@ -332,7 +332,7 @@ dependencies = [
332
  "aws-smithy-http",
333
  "aws-smithy-runtime-api",
334
  "aws-smithy-types",
335
- "bytes",
336
  "form_urlencoded",
337
  "hex",
338
  "hmac",
@@ -363,7 +363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
363
  checksum = "1c669e1e5fc0d79561bf7a122b118bd50c898758354fe2c53eb8f2d31507cbc3"
364
  dependencies = [
365
  "aws-smithy-types",
366
- "bytes",
367
  "crc32fast",
368
  ]
369
 
@@ -376,7 +376,7 @@ dependencies = [
376
  "aws-smithy-eventstream",
377
  "aws-smithy-runtime-api",
378
  "aws-smithy-types",
379
- "bytes",
380
  "bytes-utils",
381
  "futures-core",
382
  "http",
@@ -417,7 +417,7 @@ dependencies = [
417
  "aws-smithy-http",
418
  "aws-smithy-runtime-api",
419
  "aws-smithy-types",
420
- "bytes",
421
  "fastrand",
422
  "http",
423
  "http-body",
@@ -439,7 +439,7 @@ checksum = "4d27c3235d4972ed976b5c1a82286e7c4457f618f3c2ae6d4ae44f081dd24575"
439
  dependencies = [
440
  "aws-smithy-async",
441
  "aws-smithy-types",
442
- "bytes",
443
  "http",
444
  "pin-project-lite",
445
  "tokio",
@@ -454,7 +454,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
454
  checksum = "d2fc32035dc0636a8583cf0c6dd7f1e6d5404103b836d26228b8730907a88d9f"
455
  dependencies = [
456
  "base64-simd",
457
- "bytes",
458
  "bytes-utils",
459
  "futures-core",
460
  "http",
@@ -604,6 +604,12 @@ version = "1.5.0"
604
  source = "registry+https://github.com/rust-lang/crates.io-index"
605
  checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
606
 
 
 
 
 
 
 
607
  [[package]]
608
  name = "bytes"
609
  version = "1.5.0"
@@ -616,7 +622,7 @@ version = "0.1.4"
616
  source = "registry+https://github.com/rust-lang/crates.io-index"
617
  checksum = "7dafe3a8757b027e2be6e4e5601ed563c55989fcf1546e933c66c8eb3a058d35"
618
  dependencies = [
619
- "bytes",
620
  "either",
621
  ]
622
 
@@ -845,6 +851,21 @@ version = "1.3.0"
845
  source = "registry+https://github.com/rust-lang/crates.io-index"
846
  checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
847
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
848
  [[package]]
849
  name = "futures-channel"
850
  version = "0.3.29"
@@ -852,6 +873,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
852
  checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
853
  dependencies = [
854
  "futures-core",
 
855
  ]
856
 
857
  [[package]]
@@ -860,6 +882,23 @@ version = "0.3.29"
860
  source = "registry+https://github.com/rust-lang/crates.io-index"
861
  checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
862
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
863
  [[package]]
864
  name = "futures-macro"
865
  version = "0.3.29"
@@ -889,15 +928,30 @@ version = "0.3.29"
889
  source = "registry+https://github.com/rust-lang/crates.io-index"
890
  checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
891
  dependencies = [
 
892
  "futures-core",
 
893
  "futures-macro",
894
  "futures-sink",
895
  "futures-task",
 
896
  "pin-project-lite",
897
  "pin-utils",
898
  "slab",
899
  ]
900
 
 
 
 
 
 
 
 
 
 
 
 
 
901
  [[package]]
902
  name = "fvad"
903
  version = "0.1.3"
@@ -946,7 +1000,7 @@ version = "0.3.22"
946
  source = "registry+https://github.com/rust-lang/crates.io-index"
947
  checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178"
948
  dependencies = [
949
- "bytes",
950
  "fnv",
951
  "futures-core",
952
  "futures-sink",
@@ -981,7 +1035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
981
  checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270"
982
  dependencies = [
983
  "base64 0.21.5",
984
- "bytes",
985
  "headers-core",
986
  "http",
987
  "httpdate",
@@ -1037,13 +1091,19 @@ dependencies = [
1037
  "windows-sys",
1038
  ]
1039
 
 
 
 
 
 
 
1040
  [[package]]
1041
  name = "http"
1042
  version = "0.2.11"
1043
  source = "registry+https://github.com/rust-lang/crates.io-index"
1044
  checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb"
1045
  dependencies = [
1046
- "bytes",
1047
  "fnv",
1048
  "itoa",
1049
  ]
@@ -1054,7 +1114,7 @@ version = "0.4.5"
1054
  source = "registry+https://github.com/rust-lang/crates.io-index"
1055
  checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
1056
  dependencies = [
1057
- "bytes",
1058
  "http",
1059
  "pin-project-lite",
1060
  ]
@@ -1083,7 +1143,7 @@ version = "0.14.27"
1083
  source = "registry+https://github.com/rust-lang/crates.io-index"
1084
  checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468"
1085
  dependencies = [
1086
- "bytes",
1087
  "futures-channel",
1088
  "futures-core",
1089
  "futures-util",
@@ -1476,6 +1536,26 @@ dependencies = [
1476
  "sha2",
1477
  ]
1478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1479
  [[package]]
1480
  name = "pin-project-lite"
1481
  version = "0.2.13"
@@ -1496,7 +1576,7 @@ checksum = "504774c97b0744c1ee108a37e5a65a9745a4725c4c06277521dabc28eb53a904"
1496
  dependencies = [
1497
  "async-trait",
1498
  "base64 0.21.5",
1499
- "bytes",
1500
  "futures-util",
1501
  "headers",
1502
  "http",
@@ -1515,8 +1595,10 @@ dependencies = [
1515
  "serde_json",
1516
  "serde_urlencoded",
1517
  "smallvec",
 
1518
  "thiserror",
1519
  "tokio",
 
1520
  "tokio-tungstenite",
1521
  "tokio-util",
1522
  "tracing",
@@ -1549,6 +1631,7 @@ dependencies = [
1549
  "base64 0.21.5",
1550
  "config",
1551
  "futures-util",
 
1552
  "lazy_static",
1553
  "once_cell",
1554
  "poem",
@@ -1557,6 +1640,7 @@ dependencies = [
1557
  "serde_yaml",
1558
  "tokio",
1559
  "tokio-stream",
 
1560
  "tracing",
1561
  "tracing-subscriber",
1562
  "tracing-test",
@@ -2025,6 +2109,18 @@ version = "0.9.8"
2025
  source = "registry+https://github.com/rust-lang/crates.io-index"
2026
  checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
2027
 
 
 
 
 
 
 
 
 
 
 
 
 
2028
  [[package]]
2029
  name = "strsim"
2030
  version = "0.8.0"
@@ -2157,7 +2253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2157
  checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
2158
  dependencies = [
2159
  "backtrace",
2160
- "bytes",
2161
  "libc",
2162
  "mio",
2163
  "num_cpus",
@@ -2218,8 +2314,9 @@ version = "0.7.10"
2218
  source = "registry+https://github.com/rust-lang/crates.io-index"
2219
  checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
2220
  dependencies = [
2221
- "bytes",
2222
  "futures-core",
 
2223
  "futures-sink",
2224
  "pin-project-lite",
2225
  "tokio",
@@ -2355,7 +2452,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2355
  checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9"
2356
  dependencies = [
2357
  "byteorder",
2358
- "bytes",
2359
  "data-encoding",
2360
  "http",
2361
  "httparse",
 
121
  "aws-smithy-runtime-api",
122
  "aws-smithy-types",
123
  "aws-types",
124
+ "bytes 1.5.0",
125
  "fastrand",
126
  "hex",
127
  "http",
 
154
  "aws-smithy-runtime-api",
155
  "aws-smithy-types",
156
  "aws-types",
157
+ "bytes 1.5.0",
158
  "http",
159
  "http-body",
160
  "pin-project-lite",
 
200
  "aws-smithy-runtime-api",
201
  "aws-smithy-types",
202
  "aws-types",
203
+ "bytes 1.5.0",
204
  "http",
205
  "regex",
206
  "tracing",
 
222
  "aws-smithy-runtime-api",
223
  "aws-smithy-types",
224
  "aws-types",
225
+ "bytes 1.5.0",
226
  "http",
227
  "regex",
228
  "tracing",
 
244
  "aws-smithy-runtime-api",
245
  "aws-smithy-types",
246
  "aws-types",
247
+ "bytes 1.5.0",
248
  "http",
249
  "regex",
250
  "tracing",
 
291
  "aws-smithy-runtime-api",
292
  "aws-smithy-types",
293
  "aws-types",
294
+ "bytes 1.5.0",
295
  "http",
296
  "hyper",
297
  "regex",
 
314
  "aws-smithy-runtime-api",
315
  "aws-smithy-types",
316
  "aws-types",
317
+ "bytes 1.5.0",
318
  "fastrand",
319
  "http",
320
  "regex",
 
332
  "aws-smithy-http",
333
  "aws-smithy-runtime-api",
334
  "aws-smithy-types",
335
+ "bytes 1.5.0",
336
  "form_urlencoded",
337
  "hex",
338
  "hmac",
 
363
  checksum = "1c669e1e5fc0d79561bf7a122b118bd50c898758354fe2c53eb8f2d31507cbc3"
364
  dependencies = [
365
  "aws-smithy-types",
366
+ "bytes 1.5.0",
367
  "crc32fast",
368
  ]
369
 
 
376
  "aws-smithy-eventstream",
377
  "aws-smithy-runtime-api",
378
  "aws-smithy-types",
379
+ "bytes 1.5.0",
380
  "bytes-utils",
381
  "futures-core",
382
  "http",
 
417
  "aws-smithy-http",
418
  "aws-smithy-runtime-api",
419
  "aws-smithy-types",
420
+ "bytes 1.5.0",
421
  "fastrand",
422
  "http",
423
  "http-body",
 
439
  dependencies = [
440
  "aws-smithy-async",
441
  "aws-smithy-types",
442
+ "bytes 1.5.0",
443
  "http",
444
  "pin-project-lite",
445
  "tokio",
 
454
  checksum = "d2fc32035dc0636a8583cf0c6dd7f1e6d5404103b836d26228b8730907a88d9f"
455
  dependencies = [
456
  "base64-simd",
457
+ "bytes 1.5.0",
458
  "bytes-utils",
459
  "futures-core",
460
  "http",
 
604
  source = "registry+https://github.com/rust-lang/crates.io-index"
605
  checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
606
 
607
+ [[package]]
608
+ name = "bytes"
609
+ version = "0.5.6"
610
+ source = "registry+https://github.com/rust-lang/crates.io-index"
611
+ checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
612
+
613
  [[package]]
614
  name = "bytes"
615
  version = "1.5.0"
 
622
  source = "registry+https://github.com/rust-lang/crates.io-index"
623
  checksum = "7dafe3a8757b027e2be6e4e5601ed563c55989fcf1546e933c66c8eb3a058d35"
624
  dependencies = [
625
+ "bytes 1.5.0",
626
  "either",
627
  ]
628
 
 
851
  source = "registry+https://github.com/rust-lang/crates.io-index"
852
  checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
853
 
854
+ [[package]]
855
+ name = "futures"
856
+ version = "0.3.28"
857
+ source = "registry+https://github.com/rust-lang/crates.io-index"
858
+ checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
859
+ dependencies = [
860
+ "futures-channel",
861
+ "futures-core",
862
+ "futures-executor",
863
+ "futures-io",
864
+ "futures-sink",
865
+ "futures-task",
866
+ "futures-util",
867
+ ]
868
+
869
  [[package]]
870
  name = "futures-channel"
871
  version = "0.3.29"
 
873
  checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
874
  dependencies = [
875
  "futures-core",
876
+ "futures-sink",
877
  ]
878
 
879
  [[package]]
 
882
  source = "registry+https://github.com/rust-lang/crates.io-index"
883
  checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
884
 
885
+ [[package]]
886
+ name = "futures-executor"
887
+ version = "0.3.29"
888
+ source = "registry+https://github.com/rust-lang/crates.io-index"
889
+ checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc"
890
+ dependencies = [
891
+ "futures-core",
892
+ "futures-task",
893
+ "futures-util",
894
+ ]
895
+
896
+ [[package]]
897
+ name = "futures-io"
898
+ version = "0.3.29"
899
+ source = "registry+https://github.com/rust-lang/crates.io-index"
900
+ checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
901
+
902
  [[package]]
903
  name = "futures-macro"
904
  version = "0.3.29"
 
928
  source = "registry+https://github.com/rust-lang/crates.io-index"
929
  checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
930
  dependencies = [
931
+ "futures-channel",
932
  "futures-core",
933
+ "futures-io",
934
  "futures-macro",
935
  "futures-sink",
936
  "futures-task",
937
+ "memchr",
938
  "pin-project-lite",
939
  "pin-utils",
940
  "slab",
941
  ]
942
 
943
+ [[package]]
944
+ name = "futures_codec"
945
+ version = "0.4.1"
946
+ source = "registry+https://github.com/rust-lang/crates.io-index"
947
+ checksum = "ce54d63f8b0c75023ed920d46fd71d0cbbb830b0ee012726b5b4f506fb6dea5b"
948
+ dependencies = [
949
+ "bytes 0.5.6",
950
+ "futures",
951
+ "memchr",
952
+ "pin-project",
953
+ ]
954
+
955
  [[package]]
956
  name = "fvad"
957
  version = "0.1.3"
 
1000
  source = "registry+https://github.com/rust-lang/crates.io-index"
1001
  checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178"
1002
  dependencies = [
1003
+ "bytes 1.5.0",
1004
  "fnv",
1005
  "futures-core",
1006
  "futures-sink",
 
1035
  checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270"
1036
  dependencies = [
1037
  "base64 0.21.5",
1038
+ "bytes 1.5.0",
1039
  "headers-core",
1040
  "http",
1041
  "httpdate",
 
1091
  "windows-sys",
1092
  ]
1093
 
1094
+ [[package]]
1095
+ name = "hound"
1096
+ version = "3.5.1"
1097
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1098
+ checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
1099
+
1100
  [[package]]
1101
  name = "http"
1102
  version = "0.2.11"
1103
  source = "registry+https://github.com/rust-lang/crates.io-index"
1104
  checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb"
1105
  dependencies = [
1106
+ "bytes 1.5.0",
1107
  "fnv",
1108
  "itoa",
1109
  ]
 
1114
  source = "registry+https://github.com/rust-lang/crates.io-index"
1115
  checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
1116
  dependencies = [
1117
+ "bytes 1.5.0",
1118
  "http",
1119
  "pin-project-lite",
1120
  ]
 
1143
  source = "registry+https://github.com/rust-lang/crates.io-index"
1144
  checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468"
1145
  dependencies = [
1146
+ "bytes 1.5.0",
1147
  "futures-channel",
1148
  "futures-core",
1149
  "futures-util",
 
1536
  "sha2",
1537
  ]
1538
 
1539
+ [[package]]
1540
+ name = "pin-project"
1541
+ version = "0.4.30"
1542
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1543
+ checksum = "3ef0f924a5ee7ea9cbcea77529dba45f8a9ba9f622419fe3386ca581a3ae9d5a"
1544
+ dependencies = [
1545
+ "pin-project-internal",
1546
+ ]
1547
+
1548
+ [[package]]
1549
+ name = "pin-project-internal"
1550
+ version = "0.4.30"
1551
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1552
+ checksum = "851c8d0ce9bebe43790dedfc86614c23494ac9f423dd618d3a61fc693eafe61e"
1553
+ dependencies = [
1554
+ "proc-macro2",
1555
+ "quote",
1556
+ "syn 1.0.109",
1557
+ ]
1558
+
1559
  [[package]]
1560
  name = "pin-project-lite"
1561
  version = "0.2.13"
 
1576
  dependencies = [
1577
  "async-trait",
1578
  "base64 0.21.5",
1579
+ "bytes 1.5.0",
1580
  "futures-util",
1581
  "headers",
1582
  "http",
 
1595
  "serde_json",
1596
  "serde_urlencoded",
1597
  "smallvec",
1598
+ "sse-codec",
1599
  "thiserror",
1600
  "tokio",
1601
+ "tokio-stream",
1602
  "tokio-tungstenite",
1603
  "tokio-util",
1604
  "tracing",
 
1631
  "base64 0.21.5",
1632
  "config",
1633
  "futures-util",
1634
+ "hound",
1635
  "lazy_static",
1636
  "once_cell",
1637
  "poem",
 
1640
  "serde_yaml",
1641
  "tokio",
1642
  "tokio-stream",
1643
+ "tokio-tungstenite",
1644
  "tracing",
1645
  "tracing-subscriber",
1646
  "tracing-test",
 
2109
  source = "registry+https://github.com/rust-lang/crates.io-index"
2110
  checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
2111
 
2112
+ [[package]]
2113
+ name = "sse-codec"
2114
+ version = "0.3.2"
2115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2116
+ checksum = "84a59f811350c44b4a037aabeb72dc6a9591fc22aa95a036db9a96297c58085a"
2117
+ dependencies = [
2118
+ "bytes 0.5.6",
2119
+ "futures-io",
2120
+ "futures_codec",
2121
+ "memchr",
2122
+ ]
2123
+
2124
  [[package]]
2125
  name = "strsim"
2126
  version = "0.8.0"
 
2253
  checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
2254
  dependencies = [
2255
  "backtrace",
2256
+ "bytes 1.5.0",
2257
  "libc",
2258
  "mio",
2259
  "num_cpus",
 
2314
  source = "registry+https://github.com/rust-lang/crates.io-index"
2315
  checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
2316
  dependencies = [
2317
+ "bytes 1.5.0",
2318
  "futures-core",
2319
+ "futures-io",
2320
  "futures-sink",
2321
  "pin-project-lite",
2322
  "tokio",
 
2452
  checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9"
2453
  dependencies = [
2454
  "byteorder",
2455
+ "bytes 1.5.0",
2456
  "data-encoding",
2457
  "http",
2458
  "httparse",
Cargo.toml CHANGED
@@ -39,3 +39,6 @@ whisper = { path="whisper", features = ["cuda"], optional = true }
39
 
40
  [dev-dependencies]
41
  tracing-test = "*"
 
 
 
 
39
 
40
  [dev-dependencies]
41
  tracing-test = "*"
42
+ poem = { version = "1.3", features = ["websocket", "static-files", "test"] }
43
+ tokio-tungstenite = "*"
44
+ hound = "*"
src/asr/aws.rs CHANGED
@@ -12,7 +12,7 @@ use tokio::select;
12
  use tokio::sync::broadcast::Receiver;
13
  use tokio_stream::Stream;
14
  use futures_util::TryStreamExt;
15
- use crate::asr::{ASR, Event};
16
 
17
  pub struct AwsAsr {
18
  speaker_voice_channel: tokio::sync::mpsc::Sender<Vec<i16>>,
@@ -82,16 +82,6 @@ impl AwsAsr {
82
  }
83
  }
84
 
85
- #[allow(dead_code)]
86
- fn slice_i16_to_u8(slice: &[i16]) -> Vec<u8> {
87
- slice
88
- .iter()
89
- .flat_map(|&sample| {
90
- [sample as u8, (sample >> 8) as u8]
91
- })
92
- .collect()
93
- }
94
-
95
  impl Drop for AwsAsr {
96
  fn drop(&mut self) {
97
  if let Some(drop_handler) = self.drop_handler.take() {
 
12
  use tokio::sync::broadcast::Receiver;
13
  use tokio_stream::Stream;
14
  use futures_util::TryStreamExt;
15
+ use crate::asr::{ASR, Event, slice_i16_to_u8};
16
 
17
  pub struct AwsAsr {
18
  speaker_voice_channel: tokio::sync::mpsc::Sender<Vec<i16>>,
 
82
  }
83
  }
84
 
 
 
 
 
 
 
 
 
 
 
85
  impl Drop for AwsAsr {
86
  fn drop(&mut self) {
87
  if let Some(drop_handler) = self.drop_handler.take() {
src/asr/mod.rs CHANGED
@@ -16,3 +16,15 @@ pub(crate) trait ASR {
16
  async fn frame(&mut self, frame: Vec<i16>) -> anyhow::Result<()>;
17
  fn subscribe(&mut self) -> Receiver<Event>;
18
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  async fn frame(&mut self, frame: Vec<i16>) -> anyhow::Result<()>;
17
  fn subscribe(&mut self) -> Receiver<Event>;
18
  }
19
+
20
+
21
+ #[allow(dead_code)]
22
+ pub(crate) fn slice_i16_to_u8(slice: &[i16]) -> Vec<u8> {
23
+ slice
24
+ .iter()
25
+ .flat_map(|&sample| {
26
+ [sample as u8, (sample >> 8) as u8]
27
+ })
28
+ .collect()
29
+ }
30
+
src/main.rs CHANGED
@@ -276,7 +276,7 @@ async fn stream_listener(
276
  })
277
  }
278
 
279
- #[derive(Serialize, Debug)]
280
  enum SingleEvent {
281
  #[serde(rename = "original")]
282
  Transcription {
@@ -403,4 +403,127 @@ fn u8_to_i16(input: &[u8]) -> Vec<i16> {
403
  i16::from_le_bytes(buf)
404
  })
405
  .collect::<Vec<i16>>()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  }
 
276
  })
277
  }
278
 
279
+ #[derive(Serialize, Deserialize, Debug)]
280
  enum SingleEvent {
281
  #[serde(rename = "original")]
282
  Transcription {
 
403
  i16::from_le_bytes(buf)
404
  })
405
  .collect::<Vec<i16>>()
406
+ }
407
+
408
+ #[cfg(test)]
409
+ mod test {
410
+ use std::cell::{Cell};
411
+ use std::time::Duration;
412
+ use async_stream::stream;
413
+ use poem::listener::{Acceptor, Listener};
414
+ use tokio::pin;
415
+ use tokio::time::sleep;
416
+ use tokio_stream::StreamExt;
417
+ use tokio_tungstenite::{
418
+ connect_async,
419
+ tungstenite::Message,
420
+ };
421
+ use tracing::{info, error};
422
+ use crate::asr::slice_i16_to_u8;
423
+ use super::*;
424
+
425
+ #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
426
+ #[tracing_test::traced_test]
427
+ async fn test_single() {
428
+ let shared_config = aws_config::load_defaults(BehaviorVersion::latest()).await;
429
+ let ctx = Context {
430
+ lessons_manager: LessonsManager::new(&shared_config),
431
+ };
432
+
433
+ let query = SingleQuery {
434
+ id: 1,
435
+ from: "zh-CN".to_string(),
436
+ to: "en-US".to_string(),
437
+ voice: None,
438
+ };
439
+
440
+ let acceptor = TcpListener::bind("[::]:0")
441
+ .into_acceptor()
442
+ .await
443
+ .unwrap();
444
+ let addr = acceptor
445
+ .local_addr()
446
+ .remove(0)
447
+ .as_socket_addr()
448
+ .cloned()
449
+ .unwrap();
450
+ let server = Server::new_with_acceptor(acceptor);
451
+ let handle = tokio::spawn(async move {
452
+ let _ = server.run(
453
+ Route::new()
454
+ .at("/ws/voice", get(stream_single))
455
+ .data(ctx)
456
+ ).await;
457
+ });
458
+
459
+ let url = format!(
460
+ "ws://{}/ws/voice?id={}&from={}&to={}&voice={}",
461
+ addr, query.id, query.from, query.to, query.voice.unwrap_or("Amy".to_string())
462
+ );
463
+ let (mut client_stream, _) = connect_async(url)
464
+ .await
465
+ .unwrap();
466
+
467
+ client_stream
468
+ .send(Message::Binary(Vec::new()))
469
+ .await
470
+ .unwrap();
471
+
472
+
473
+ let wav = hound::WavReader::open("whisper/samples/samples_jfk.wav")
474
+ .expect("failed to open wav");
475
+ let spec = wav.spec();
476
+ info!("{:?}", spec);
477
+ let samples = wav
478
+ .into_samples::<i16>()
479
+ .map(|s| s.unwrap())
480
+ .collect::<Vec<i16>>();
481
+ let chunks = samples.chunks(1600)
482
+ .map(|chunk| chunk.to_vec())
483
+ .into_iter();
484
+
485
+ let audio_stream = stream! {
486
+ for chunk in chunks {
487
+ yield slice_i16_to_u8(&chunk);
488
+ sleep(Duration::from_millis(10)).await;
489
+ }
490
+ };
491
+ pin!(audio_stream);
492
+
493
+ let voice_flag = Cell::new(false);
494
+ let recv_fut = async {
495
+ while let Some(voice_slice) = audio_stream.next().await {
496
+ client_stream.send(Message::Binary(voice_slice)).await?;
497
+ }
498
+ info!("sent all voice chunks");
499
+
500
+ while let Some(next_msg) = client_stream.next().await {
501
+ debug!(?next_msg);
502
+ let msg = next_msg?;
503
+ let Message::Text(json_str) = msg else { continue };
504
+ let Ok(evt) = serde_json::from_str::<SingleEvent>(&json_str) else { continue };
505
+ if let SingleEvent::Voice { .. } = evt {
506
+ voice_flag.replace(true);
507
+ break
508
+ }
509
+ }
510
+
511
+ Ok(()) as anyhow::Result<()>
512
+ };
513
+
514
+ select! {
515
+ res = recv_fut => {
516
+ if let Err(e) = res {
517
+ error!("Error: {:?}", e);
518
+ }
519
+ }
520
+ _ = sleep(Duration::from_secs(10)) => {
521
+ error!("timeout")
522
+ }
523
+ }
524
+
525
+ handle.abort();
526
+
527
+ assert!(voice_flag.get(), "voice not received");
528
+ }
529
  }
whisper/samples/samples_jfk.wav ADDED
Binary file (352 kB). View file