Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
RapidASR
Commits
5737fff6
Commit
5737fff6
authored
Mar 08, 2023
by
mayong
Browse files
bugfix: RTF
parent
959796fb
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
315 additions
and
0 deletions
+315
-0
cpp_onnx/include/librapidasrapi.h
cpp_onnx/include/librapidasrapi.h
+96
-0
cpp_onnx/src/librapidasrapi.cpp
cpp_onnx/src/librapidasrapi.cpp
+219
-0
cpp_onnx/wave/test.pcm.bytes
cpp_onnx/wave/test.pcm.bytes
+0
-0
cpp_onnx/wave/test.pcm.wav
cpp_onnx/wave/test.pcm.wav
+0
-0
No files found.
cpp_onnx/include/librapidasrapi.h
0 → 100644
View file @
5737fff6
#pragma once
#ifdef WIN32
#ifdef _RPASR_API_EXPORT
#define _RAPIDASRAPI __declspec(dllexport)
#else
#define _RAPIDASRAPI __declspec(dllimport)
#endif
#else
#define _RAPIDASRAPI
#endif
#ifndef _WIN32
#define RPASR_CALLBCK_PREFIX __attribute__((__stdcall__))
#else
#define RPASR_CALLBCK_PREFIX __stdcall
#endif
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
void
*
RPASR_HANDLE
;
typedef
void
*
RPASR_RESULT
;
typedef
unsigned
char
RPASR_BOOL
;
#define RPASR_TRUE 1
#define RPASR_FALSE 0
#define QM_DEFAULT_THREAD_NUM 4
typedef
enum
{
RASR_NONE
=-
1
,
RASRM_CTC_GREEDY_SEARCH
=
0
,
RASRM_CTC_RPEFIX_BEAM_SEARCH
=
1
,
RASRM_ATTENSION_RESCORING
=
2
,
}
RPASR_MODE
;
typedef
enum
{
RPASR_MODEL_PADDLE
=
0
,
RPASR_MODEL_PADDLE_2
=
1
,
RPASR_MODEL_K2
=
2
,
RPASR_MODEL_PARAFORMER
=
3
,
}
RPASR_MODEL_TYPE
;
typedef
void
(
*
QM_CALLBACK
)(
int
nCurStep
,
int
nTotal
);
// nTotal: total steps; nCurStep: Current Step.
// APIs for qmasr
_RAPIDASRAPI
RPASR_HANDLE
RapidAsrInit
(
const
char
*
szModelDir
,
int
nThread
);
// if not give a fnCallback ,it should be NULL
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogBuffer
(
RPASR_HANDLE
handle
,
const
char
*
szBuf
,
int
nLen
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
);
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogPCMBuffer
(
RPASR_HANDLE
handle
,
const
char
*
szBuf
,
int
nLen
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
);
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogPCMFile
(
RPASR_HANDLE
handle
,
const
char
*
szFileName
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
);
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogFile
(
RPASR_HANDLE
handle
,
const
char
*
szWavfile
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
);
_RAPIDASRAPI
const
char
*
RapidAsrGetResult
(
RPASR_RESULT
Result
,
int
nIndex
);
_RAPIDASRAPI
const
int
RapidAsrGetRetNumber
(
RPASR_RESULT
Result
);
_RAPIDASRAPI
void
RapidAsrFreeResult
(
RPASR_RESULT
Result
);
_RAPIDASRAPI
void
RapidAsrUninit
(
RPASR_HANDLE
Handle
);
_RAPIDASRAPI
const
float
RapidAsrGetRetSnippetTime
(
RPASR_RESULT
Result
);
#ifdef __cplusplus
}
#endif
\ No newline at end of file
cpp_onnx/src/librapidasrapi.cpp
0 → 100644
View file @
5737fff6
#include "precomp.h"
#ifdef __cplusplus
// void __attribute__ ((visibility ("default"))) fun();
extern
"C"
{
#endif
// APIs for qmasr
_RAPIDASRAPI
RPASR_HANDLE
RapidAsrInit
(
const
char
*
szModelDir
,
int
nThreadNum
)
{
#ifdef NDEBUG
QMLIC_BOOL
bMatched
=
QmLicCheckValid
(
QLFM_ASR
);
if
(
!
bMatched
)
{
return
nullptr
;
}
#endif
Model
*
mm
=
create_model
(
szModelDir
,
nThreadNum
);
return
mm
;
}
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogBuffer
(
RPASR_HANDLE
handle
,
const
char
*
szBuf
,
int
nLen
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
)
{
Model
*
pRecogObj
=
(
Model
*
)
handle
;
if
(
!
pRecogObj
)
return
nullptr
;
Audio
audio
(
1
);
audio
.
loadwav
(
szBuf
,
nLen
);
audio
.
split
();
float
*
buff
;
int
len
;
int
flag
=
0
;
RPASR_RECOG_RESULT
*
pResult
=
new
RPASR_RECOG_RESULT
;
pResult
->
snippet_time
=
audio
.
get_time_len
();
int
nStep
=
0
;
int
nTotal
=
audio
.
get_queue_size
();
while
(
audio
.
fetch
(
buff
,
len
,
flag
)
>
0
)
{
pRecogObj
->
reset
();
string
msg
=
pRecogObj
->
forward
(
buff
,
len
,
flag
);
pResult
->
msg
+=
msg
;
nStep
++
;
if
(
fnCallback
)
fnCallback
(
nStep
,
nTotal
);
}
return
pResult
;
}
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogPCMBuffer
(
RPASR_HANDLE
handle
,
const
char
*
szBuf
,
int
nLen
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
)
{
Model
*
pRecogObj
=
(
Model
*
)
handle
;
if
(
!
pRecogObj
)
return
nullptr
;
Audio
audio
(
1
);
audio
.
loadpcmwav
(
szBuf
,
nLen
);
audio
.
split
();
float
*
buff
;
int
len
;
int
flag
=
0
;
RPASR_RECOG_RESULT
*
pResult
=
new
RPASR_RECOG_RESULT
;
pResult
->
snippet_time
=
audio
.
get_time_len
();
int
nStep
=
0
;
int
nTotal
=
audio
.
get_queue_size
();
while
(
audio
.
fetch
(
buff
,
len
,
flag
)
>
0
)
{
pRecogObj
->
reset
();
string
msg
=
pRecogObj
->
forward
(
buff
,
len
,
flag
);
pResult
->
msg
+=
msg
;
nStep
++
;
if
(
fnCallback
)
fnCallback
(
nStep
,
nTotal
);
}
return
pResult
;
}
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogPCMFile
(
RPASR_HANDLE
handle
,
const
char
*
szFileName
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
)
{
Model
*
pRecogObj
=
(
Model
*
)
handle
;
if
(
!
pRecogObj
)
return
nullptr
;
Audio
audio
(
1
);
audio
.
loadpcmwav
(
szFileName
);
audio
.
split
();
float
*
buff
;
int
len
;
int
flag
=
0
;
RPASR_RECOG_RESULT
*
pResult
=
new
RPASR_RECOG_RESULT
;
pResult
->
snippet_time
=
audio
.
get_time_len
();
int
nStep
=
0
;
int
nTotal
=
audio
.
get_queue_size
();
while
(
audio
.
fetch
(
buff
,
len
,
flag
)
>
0
)
{
pRecogObj
->
reset
();
string
msg
=
pRecogObj
->
forward
(
buff
,
len
,
flag
);
pResult
->
msg
+=
msg
;
nStep
++
;
if
(
fnCallback
)
fnCallback
(
nStep
,
nTotal
);
}
return
pResult
;
}
_RAPIDASRAPI
RPASR_RESULT
RapidAsrRecogFile
(
RPASR_HANDLE
handle
,
const
char
*
szWavfile
,
RPASR_MODE
Mode
,
QM_CALLBACK
fnCallback
)
{
Model
*
pRecogObj
=
(
Model
*
)
handle
;
if
(
!
pRecogObj
)
return
nullptr
;
Audio
audio
(
1
);
if
(
!
audio
.
loadwav
(
szWavfile
))
return
nullptr
;
audio
.
split
();
float
*
buff
;
int
len
;
int
flag
=
0
;
int
nStep
=
0
;
int
nTotal
=
audio
.
get_queue_size
();
RPASR_RECOG_RESULT
*
pResult
=
new
RPASR_RECOG_RESULT
;
pResult
->
snippet_time
=
audio
.
get_time_len
();
while
(
audio
.
fetch
(
buff
,
len
,
flag
)
>
0
)
{
pRecogObj
->
reset
();
string
msg
=
pRecogObj
->
forward
(
buff
,
len
,
flag
);
pResult
->
msg
+=
msg
;
nStep
++
;
if
(
fnCallback
)
fnCallback
(
nStep
,
nTotal
);
}
return
pResult
;
}
_RAPIDASRAPI
const
int
RapidAsrGetRetNumber
(
RPASR_RESULT
Result
)
{
if
(
!
Result
)
return
0
;
return
1
;
}
_RAPIDASRAPI
const
float
RapidAsrGetRetSnippetTime
(
RPASR_RESULT
Result
)
{
if
(
!
Result
)
return
0.0
f
;
return
((
RPASR_RECOG_RESULT
*
)
Result
)
->
snippet_time
;
}
_RAPIDASRAPI
const
char
*
RapidAsrGetResult
(
RPASR_RESULT
Result
,
int
nIndex
)
{
RPASR_RECOG_RESULT
*
pResult
=
(
RPASR_RECOG_RESULT
*
)
Result
;
if
(
!
pResult
)
return
nullptr
;
return
pResult
->
msg
.
c_str
();
}
_RAPIDASRAPI
void
RapidAsrFreeResult
(
RPASR_RESULT
Result
)
{
if
(
Result
)
{
delete
(
RPASR_RECOG_RESULT
*
)
Result
;
}
}
_RAPIDASRAPI
void
RapidAsrUninit
(
RPASR_HANDLE
handle
)
{
Model
*
pRecogObj
=
(
Model
*
)
handle
;
if
(
!
pRecogObj
)
return
;
delete
pRecogObj
;
}
#ifdef __cplusplus
}
#endif
cpp_onnx/wave/test.pcm.bytes
0 → 100644
View file @
5737fff6
File added
cpp_onnx/wave/test.pcm.wav
0 → 100644
View file @
5737fff6
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment