forked from k2-fsa/sherpa-onnx
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.dart
30 lines (25 loc) · 807 Bytes
/
init.dart
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
// Copyright (c) 2024 Xiaomi Corporation
import 'dart:io';
import 'dart:isolate';
import 'package:path/path.dart' as p;
import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx;
Future<void> initSherpaOnnx() async {
String platform = '';
if (Platform.isMacOS) {
platform = 'macos';
} else if (Platform.isLinux) {
platform = 'linux';
} else if (Platform.isWindows) {
platform = 'windows';
} else {
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}
var uri = await Isolate.resolvePackageUri(
Uri.parse('package:sherpa_onnx_$platform/any_path_is_ok_here.dart'));
if (uri == null) {
print('File not found');
exit(1);
}
final libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform);
sherpa_onnx.initBindings(libPath);
}