Skip to content

Commit 07c119a

Browse files
authored
Use file path to initialize onnxruntime session. (#3482)
1 parent 27c8da5 commit 07c119a

139 files changed

Lines changed: 1394 additions & 622 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sherpa-onnx/csrc/alsa-play.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifdef SHERPA_ONNX_ENABLE_ALSA
66

77
#include "sherpa-onnx/csrc/alsa-play.h"
8+
#include "sherpa-onnx/csrc/macros.h"
89

910
#include <algorithm>
1011
#include <cstdio>
@@ -18,7 +19,7 @@ AlsaPlay::AlsaPlay(const char *device_name, int32_t sample_rate) {
1819

1920
if (err) {
2021
fprintf(stderr, "Unable to open: %s. %s\n", device_name, snd_strerror(err));
21-
exit(-1);
22+
SHERPA_ONNX_EXIT(-1);
2223
}
2324

2425
SetParameters(sample_rate);
@@ -47,14 +48,14 @@ void AlsaPlay::SetParameters(int32_t sample_rate) {
4748
if (err < 0) {
4849
printf("SND_PCM_ACCESS_RW_INTERLEAVED is not supported: %s\n",
4950
snd_strerror(err));
50-
exit(-1);
51+
SHERPA_ONNX_EXIT(-1);
5152
}
5253

5354
err = snd_pcm_hw_params_set_format(handle_, params, SND_PCM_FORMAT_S16_LE);
5455

5556
if (err < 0) {
5657
printf("Can't set format to 16-bit: %s\n", snd_strerror(err));
57-
exit(-1);
58+
SHERPA_ONNX_EXIT(-1);
5859
}
5960

6061
err = snd_pcm_hw_params_set_channels(handle_, params, 1);
@@ -72,7 +73,7 @@ void AlsaPlay::SetParameters(int32_t sample_rate) {
7273
err = snd_pcm_hw_params(handle_, params);
7374
if (err < 0) {
7475
printf("Can't set hardware parameters. %s\n", snd_strerror(err));
75-
exit(-1);
76+
SHERPA_ONNX_EXIT(-1);
7677
}
7778

7879
uint32_t tmp;
@@ -121,7 +122,7 @@ void AlsaPlay::Play(const std::vector<float> &samples) {
121122
snd_pcm_prepare(handle_);
122123
} else if (err < 0) {
123124
printf("Can't write to PCM device: %s\n", snd_strerror(err));
124-
exit(-1);
125+
SHERPA_ONNX_EXIT(-1);
125126
}
126127
}
127128

@@ -136,7 +137,7 @@ void AlsaPlay::Play(const std::vector<float> &samples) {
136137
snd_pcm_prepare(handle_);
137138
} else if (err < 0) {
138139
printf("Can't write to PCM device: %s\n", snd_strerror(err));
139-
exit(-1);
140+
SHERPA_ONNX_EXIT(-1);
140141
}
141142
}
142143
}

sherpa-onnx/csrc/alsa.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifdef SHERPA_ONNX_ENABLE_ALSA
66

77
#include "sherpa-onnx/csrc/alsa.h"
8+
#include "sherpa-onnx/csrc/macros.h"
89

910
#include <algorithm>
1011
#include <cstdio>
@@ -49,7 +50,7 @@ and if you want to select card 3 and device 0 on that card, please use:
4950
if (err) {
5051
fprintf(stderr, "Unable to open: %s. %s\n", device_name, snd_strerror(err));
5152
fprintf(stderr, "%s\n", kDeviceHelp);
52-
exit(-1);
53+
SHERPA_ONNX_EXIT(-1);
5354
}
5455

5556
snd_pcm_hw_params_t *hw_params;
@@ -58,21 +59,21 @@ and if you want to select card 3 and device 0 on that card, please use:
5859
err = snd_pcm_hw_params_any(capture_handle_, hw_params);
5960
if (err) {
6061
fprintf(stderr, "Failed to initialize hw_params: %s\n", snd_strerror(err));
61-
exit(-1);
62+
SHERPA_ONNX_EXIT(-1);
6263
}
6364

6465
err = snd_pcm_hw_params_set_access(capture_handle_, hw_params,
6566
SND_PCM_ACCESS_RW_INTERLEAVED);
6667
if (err) {
6768
fprintf(stderr, "Failed to set access type: %s\n", snd_strerror(err));
68-
exit(-1);
69+
SHERPA_ONNX_EXIT(-1);
6970
}
7071

7172
err = snd_pcm_hw_params_set_format(capture_handle_, hw_params,
7273
SND_PCM_FORMAT_S16_LE);
7374
if (err) {
7475
fprintf(stderr, "Failed to set format: %s\n", snd_strerror(err));
75-
exit(-1);
76+
SHERPA_ONNX_EXIT(-1);
7677
}
7778

7879
// mono
@@ -86,7 +87,7 @@ and if you want to select card 3 and device 0 on that card, please use:
8687
fprintf(stderr, "Failed to set number of channels to 2. %s\n",
8788
snd_strerror(err));
8889

89-
exit(-1);
90+
SHERPA_ONNX_EXIT(-1);
9091
}
9192
actual_channel_count_ = 2;
9293
fprintf(stderr,
@@ -101,7 +102,7 @@ and if you want to select card 3 and device 0 on that card, please use:
101102
if (err) {
102103
fprintf(stderr, "Failed to set sample rate to, %d: %s\n",
103104
expected_sample_rate_, snd_strerror(err));
104-
exit(-1);
105+
SHERPA_ONNX_EXIT(-1);
105106
}
106107
actual_sample_rate_ = actual_sample_rate;
107108

@@ -128,13 +129,13 @@ and if you want to select card 3 and device 0 on that card, please use:
128129
err = snd_pcm_hw_params(capture_handle_, hw_params);
129130
if (err) {
130131
fprintf(stderr, "Failed to set hw params: %s\n", snd_strerror(err));
131-
exit(-1);
132+
SHERPA_ONNX_EXIT(-1);
132133
}
133134

134135
err = snd_pcm_prepare(capture_handle_);
135136
if (err) {
136137
fprintf(stderr, "Failed to prepare for recording: %s\n", snd_strerror(err));
137-
exit(-1);
138+
SHERPA_ONNX_EXIT(-1);
138139
}
139140

140141
fprintf(stderr, "Recording started!\n");
@@ -154,7 +155,7 @@ const std::vector<float> &Alsa::Read(int32_t num_samples) {
154155
stderr,
155156
"Too many overruns. It is very likely that the RTF on your board is "
156157
"larger than 1. Please use ./bin/sherpa-onnx to compute the RTF.\n");
157-
exit(-1);
158+
SHERPA_ONNX_EXIT(-1);
158159
}
159160
fprintf(stderr, "XRUN.\n");
160161
snd_pcm_prepare(capture_handle_);
@@ -163,7 +164,7 @@ const std::vector<float> &Alsa::Read(int32_t num_samples) {
163164
return tmp;
164165
} else if (count < 0) {
165166
fprintf(stderr, "Can't read PCM device: %s\n", snd_strerror(count));
166-
exit(-1);
167+
SHERPA_ONNX_EXIT(-1);
167168
}
168169

169170
samples_.resize(count * actual_channel_count_);

sherpa-onnx/csrc/audio-tagging-ced-impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AudioTaggingCEDImpl : public AudioTaggingImpl {
3131
if (model_.NumEventClasses() != labels_.NumEventClasses()) {
3232
SHERPA_ONNX_LOGE("number of classes: %d (model) != %d (label file)",
3333
model_.NumEventClasses(), labels_.NumEventClasses());
34-
exit(-1);
34+
SHERPA_ONNX_EXIT(-1);
3535
}
3636
}
3737

@@ -44,7 +44,7 @@ class AudioTaggingCEDImpl : public AudioTaggingImpl {
4444
if (model_.NumEventClasses() != labels_.NumEventClasses()) {
4545
SHERPA_ONNX_LOGE("number of classes: %d (model) != %d (label file)",
4646
model_.NumEventClasses(), labels_.NumEventClasses());
47-
exit(-1);
47+
SHERPA_ONNX_EXIT(-1);
4848
}
4949
}
5050
#endif

sherpa-onnx/csrc/audio-tagging-label-file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void AudioTaggingLabels::Init(std::istream &is) {
6060
int32_t i = std::stoi(index, &pos);
6161
if (index.empty() || pos != index.size()) {
6262
SHERPA_ONNX_LOGE("Invalid line: %s", line.c_str());
63-
exit(-1);
63+
SHERPA_ONNX_EXIT(-1);
6464
}
6565

6666
if (i != static_cast<int32_t>(names_.size())) {
@@ -71,7 +71,7 @@ void AudioTaggingLabels::Init(std::istream &is) {
7171
}
7272
if (name.empty() || name.front() != '"' || name.back() != '"') {
7373
SHERPA_ONNX_LOGE("Invalid line: %s", line.c_str());
74-
exit(-1);
74+
SHERPA_ONNX_EXIT(-1);
7575
}
7676

7777
names_.emplace_back(name.begin() + 1, name.end() - 1);

sherpa-onnx/csrc/audio-tagging-zipformer-impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AudioTaggingZipformerImpl : public AudioTaggingImpl {
3131
if (model_.NumEventClasses() != labels_.NumEventClasses()) {
3232
SHERPA_ONNX_LOGE("number of classes: %d (model) != %d (label file)",
3333
model_.NumEventClasses(), labels_.NumEventClasses());
34-
exit(-1);
34+
SHERPA_ONNX_EXIT(-1);
3535
}
3636
}
3737

@@ -44,7 +44,7 @@ class AudioTaggingZipformerImpl : public AudioTaggingImpl {
4444
if (model_.NumEventClasses() != labels_.NumEventClasses()) {
4545
SHERPA_ONNX_LOGE("number of classes: %d (model) != %d (label file)",
4646
model_.NumEventClasses(), labels_.NumEventClasses());
47-
exit(-1);
47+
SHERPA_ONNX_EXIT(-1);
4848
}
4949
}
5050
#endif

sherpa-onnx/csrc/base64-decode.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ static int32_t Ord(char c) {
2525

2626
SHERPA_ONNX_LOGE("Unknown character %d, %c\n", c, c);
2727

28-
exit(-1);
28+
SHERPA_ONNX_EXIT(-1);
2929
}
3030

3131
// see
3232
// https://github.com/ReneNyffenegger/cpp-base64/blob/master/base64.cpp#L243
3333
std::string Base64Decode(const std::string &s) {
3434
if (s.empty()) {
3535
SHERPA_ONNX_LOGE("Empty string!");
36-
exit(-1);
36+
SHERPA_ONNX_EXIT(-1);
3737
}
3838

3939
int32_t n = static_cast<int32_t>(s.size()) / 4 * 3;

sherpa-onnx/csrc/circular-buffer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CircularBuffer::CircularBuffer(int32_t capacity) {
1515
if (capacity <= 0) {
1616
SHERPA_ONNX_LOGE("Please specify a positive capacity. Given: %d\n",
1717
capacity);
18-
exit(-1);
18+
SHERPA_ONNX_EXIT(-1);
1919
}
2020
buffer_.resize(capacity);
2121
}

sherpa-onnx/csrc/context-graph.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ContextGraph::ForwardOneStep(const ContextState *state, int32_t token,
8888

8989
if (!node) {
9090
SHERPA_ONNX_LOGE("Some bad things happened.");
91-
exit(-1);
91+
SHERPA_ONNX_EXIT(-1);
9292
}
9393

9494
const ContextState *matched_node =

sherpa-onnx/csrc/features.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class FeatureExtractor::Impl {
9292
"You changed the input sampling rate!! Expected: %d, given: "
9393
"%d",
9494
resampler_->GetInputSamplingRate(), sampling_rate);
95-
exit(-1);
95+
SHERPA_ONNX_EXIT(-1);
9696
}
9797

9898
std::vector<float> samples;

sherpa-onnx/csrc/file-utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::vector<char> ReadFile(AAssetManager *mgr, const std::string &filename) {
6969
if (!asset) {
7070
__android_log_print(ANDROID_LOG_FATAL, "sherpa-onnx",
7171
"Read binary file: Load '%s' failed", filename.c_str());
72-
exit(-1);
72+
SHERPA_ONNX_EXIT(-1);
7373
}
7474

7575
auto p = reinterpret_cast<const char *>(AAsset_getBuffer(asset));

0 commit comments

Comments
 (0)