Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2023-06-24 00:56:53 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2023-06-24 00:56:53 +0800
Commit
157b6b801b666ecb3ded6a84184695f1e9e15258
157b6b80
1 parent
81579bbd
Fix C# APIs (#183)
* Fix c# APIs * reformat
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
84 行增加
和
56 行删除
CMakeLists.txt
c-api-examples/decode-file-c-api.c
dotnet-examples/online-decode-files/Program.cs
scripts/dotnet/online.cs
CMakeLists.txt
查看文件 @
157b6b8
cmake_minimum_required
(
VERSION 3.13 FATAL_ERROR
)
project
(
sherpa-onnx
)
set
(
SHERPA_ONNX_VERSION
"1.4.
4
"
)
set
(
SHERPA_ONNX_VERSION
"1.4.
5
"
)
# Disable warning about
#
...
...
c-api-examples/decode-file-c-api.c
查看文件 @
157b6b8
...
...
@@ -5,59 +5,54 @@
// This file shows how to use sherpa-onnx C API
// to decode a file.
#include "cargs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cargs.h"
#include "sherpa-onnx/c-api/c-api.h"
static
struct
cag_option
options
[]
=
{
{
.
identifier
=
't'
,
.
access_letters
=
NULL
,
.
access_name
=
"tokens"
,
.
value_name
=
"tokens"
,
.
description
=
"Tokens file"
},
{
.
identifier
=
'e'
,
.
access_letters
=
NULL
,
.
access_name
=
"encoder"
,
.
value_name
=
"encoder"
,
.
description
=
"Encoder ONNX file"
},
{
.
identifier
=
'd'
,
.
access_letters
=
NULL
,
.
access_name
=
"decoder"
,
.
value_name
=
"decoder"
,
.
description
=
"Decoder ONNX file"
},
{
.
identifier
=
'j'
,
.
access_letters
=
NULL
,
.
access_name
=
"joiner"
,
.
value_name
=
"joiner"
,
.
description
=
"Joiner ONNX file"
},
{
.
identifier
=
'n'
,
.
access_letters
=
NULL
,
.
access_name
=
"num-threads"
,
.
value_name
=
"num-threads"
,
.
description
=
"Number of threads"
},
{
.
identifier
=
'p'
,
.
access_letters
=
NULL
,
.
access_name
=
"provider"
,
.
value_name
=
"provider"
,
.
description
=
"Provider: cpu (default), cuda, coreml"
},
{
.
identifier
=
'm'
,
.
access_letters
=
NULL
,
.
access_name
=
"decoding-method"
,
.
value_name
=
"decoding-method"
,
.
description
=
"Decoding method: greedy_search (default), modified_beam_search"
}
};
{.
identifier
=
'h'
,
.
access_letters
=
"h"
,
.
access_name
=
"help"
,
.
description
=
"Show help"
},
{.
identifier
=
't'
,
.
access_letters
=
NULL
,
.
access_name
=
"tokens"
,
.
value_name
=
"tokens"
,
.
description
=
"Tokens file"
},
{.
identifier
=
'e'
,
.
access_letters
=
NULL
,
.
access_name
=
"encoder"
,
.
value_name
=
"encoder"
,
.
description
=
"Encoder ONNX file"
},
{.
identifier
=
'd'
,
.
access_letters
=
NULL
,
.
access_name
=
"decoder"
,
.
value_name
=
"decoder"
,
.
description
=
"Decoder ONNX file"
},
{.
identifier
=
'j'
,
.
access_letters
=
NULL
,
.
access_name
=
"joiner"
,
.
value_name
=
"joiner"
,
.
description
=
"Joiner ONNX file"
},
{.
identifier
=
'n'
,
.
access_letters
=
NULL
,
.
access_name
=
"num-threads"
,
.
value_name
=
"num-threads"
,
.
description
=
"Number of threads"
},
{.
identifier
=
'p'
,
.
access_letters
=
NULL
,
.
access_name
=
"provider"
,
.
value_name
=
"provider"
,
.
description
=
"Provider: cpu (default), cuda, coreml"
},
{.
identifier
=
'm'
,
.
access_letters
=
NULL
,
.
access_name
=
"decoding-method"
,
.
value_name
=
"decoding-method"
,
.
description
=
"Decoding method: greedy_search (default), modified_beam_search"
}};
const
char
*
kUsage
=
"
\n
"
...
...
@@ -67,6 +62,7 @@ const char *kUsage =
" --encoder=/path/to/encoder.onnx
\\\n
"
" --decoder=/path/to/decoder.onnx
\\\n
"
" --joiner=/path/to/joiner.onnx
\\\n
"
" --provider=cpu
\\\n
"
" /path/to/foo.wav
\n
"
"
\n\n
"
"Default num_threads is 1.
\n
"
...
...
@@ -77,6 +73,11 @@ const char *kUsage =
"for a list of pre-trained models to download.
\n
"
;
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
if
(
argc
<
6
)
{
fprintf
(
stderr
,
"%s
\n
"
,
kUsage
);
exit
(
0
);
}
SherpaOnnxOnlineRecognizerConfig
config
;
config
.
model_config
.
debug
=
0
;
...
...
@@ -105,19 +106,38 @@ int32_t main(int32_t argc, char *argv[]) {
identifier
=
cag_option_get
(
&
context
);
value
=
cag_option_get_value
(
&
context
);
switch
(
identifier
)
{
case
't'
:
config
.
model_config
.
tokens
=
value
;
break
;
case
'e'
:
config
.
model_config
.
encoder
=
value
;
break
;
case
'd'
:
config
.
model_config
.
decoder
=
value
;
break
;
case
'j'
:
config
.
model_config
.
joiner
=
value
;
break
;
case
'n'
:
config
.
model_config
.
num_threads
=
atoi
(
value
);
break
;
case
'p'
:
config
.
model_config
.
provider
=
value
;
break
;
case
'm'
:
config
.
decoding_method
=
value
;
break
;
default:
case
't'
:
config
.
model_config
.
tokens
=
value
;
break
;
case
'e'
:
config
.
model_config
.
encoder
=
value
;
break
;
case
'd'
:
config
.
model_config
.
decoder
=
value
;
break
;
case
'j'
:
config
.
model_config
.
joiner
=
value
;
break
;
case
'n'
:
config
.
model_config
.
num_threads
=
atoi
(
value
);
break
;
case
'p'
:
config
.
model_config
.
provider
=
value
;
break
;
case
'm'
:
config
.
decoding_method
=
value
;
break
;
case
'h'
:
{
fprintf
(
stderr
,
"%s
\n
"
,
kUsage
);
exit
(
0
);
break
;
}
default:
// do nothing as config already have valid default values
break
;
}
}
SherpaOnnxOnlineRecognizer
*
recognizer
=
CreateOnlineRecognizer
(
&
config
);
SherpaOnnxOnlineStream
*
stream
=
CreateOnlineStream
(
recognizer
);
...
...
dotnet-examples/online-decode-files/Program.cs
查看文件 @
157b6b8
...
...
@@ -20,6 +20,9 @@ class OnlineDecodeFiles
[
Option
(
Required
=
true
,
HelpText
=
"Path to tokens.txt"
)]
public
string
Tokens
{
get
;
set
;
}
[
Option
(
Required
=
false
,
Default
=
"cpu"
,
HelpText
=
"Provider, e.g., cpu, coreml"
)]
public
string
Provider
{
get
;
set
;
}
[
Option
(
Required
=
true
,
HelpText
=
"Path to encoder.onnx"
)]
public
string
Encoder
{
get
;
set
;
}
...
...
@@ -124,6 +127,7 @@ to download pre-trained streaming models.
config
.
TransducerModelConfig
.
Decoder
=
options
.
Decoder
;
config
.
TransducerModelConfig
.
Joiner
=
options
.
Joiner
;
config
.
TransducerModelConfig
.
Tokens
=
options
.
Tokens
;
config
.
TransducerModelConfig
.
Provider
=
options
.
Provider
;
config
.
TransducerModelConfig
.
NumThreads
=
options
.
NumThreads
;
config
.
TransducerModelConfig
.
Debug
=
options
.
Debug
?
1
:
0
;
...
...
scripts/dotnet/online.cs
查看文件 @
157b6b8
...
...
@@ -23,6 +23,7 @@ namespace SherpaOnnx
Joiner
=
""
;
Tokens
=
""
;
NumThreads
=
1
;
Provider
=
"cpu"
;
Debug
=
0
;
}
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
...
...
@@ -40,6 +41,9 @@ namespace SherpaOnnx
/// Number of threads used to run the neural network model
public
int
NumThreads
;
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
Provider
;
/// true to print debug information of the model
public
int
Debug
;
}
...
...
请
注册
或
登录
后发表评论