Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli/paraformer] ali-paraformer inference #2067

Merged
merged 21 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge main
  • Loading branch information
Mddct committed Oct 30, 2023
commit c11aefeb9e92c5dc954cbb236615c1871e338ef5
12 changes: 10 additions & 2 deletions wenet/cli/paraformer_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, model_dir: str) -> None:
self.char_dict = {v: k for k, v in symbol_table.items()}
self.eos = 2

def transcribe(self, audio_file: str):
def transcribe(self, audio_file: str, tokens_info: bool = False) -> dict:
waveform, sample_rate = torchaudio.load(audio_file, normalize=False)
waveform = waveform.to(torch.float)
feats = kaldi.fbank(waveform,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default window in the FunASR frontend is hamming. You can find more details here. However, the default window in kaldi.fbank is povey, as specified here. This different window maybe a little mismatch. As mentioned in line 44 of this document:

"povey" is a window I made to be similar to Hamming but to go to zero at the edges, it's pow((0.5 - 0.5cos(n/N2*pi)), 0.85) I just don't think the Hamming window makes sense as a windowing function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr welcome

Expand All @@ -36,7 +36,6 @@ def transcribe(self, audio_file: str):

res = paraformer_greedy_search(decoder_out, token_num)[0]

tokens_info = True
result = {}
result['confidence'] = res.confidence
# # TODO(Mddct): deal with '@@' and 'eos'
Expand All @@ -56,3 +55,12 @@ def transcribe(self, audio_file: str):

# result = ''.join(hyp)
return result

def align(self, audio_file: str, label: str) -> dict:
raise NotImplementedError


def load_model(language: str = None, model_dir: str = None) -> Paraformer:
if model_dir is None:
model_dir = Hub.get_model_by_lang(language)
return Paraformer(model_dir)
16 changes: 13 additions & 3 deletions wenet/cli/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import argparse

from wenet.cli.paraformer_model import load_model as load_paraformer
from wenet.cli.model import load_model


Expand All @@ -25,7 +26,6 @@ def get_args():
choices=[
'chinese',
'english',
'chinese-paraformer',
],
default='chinese',
help='language type')
Expand All @@ -41,14 +41,24 @@ def get_args():
parser.add_argument('--align',
action='store_true',
help='force align the input audio and transcript')
parser.add_argument('--label', type=str, help='the input label to align')
parser.add_argument('--label',
type=bool,
Mddct marked this conversation as resolved.
Show resolved Hide resolved
default=False,
help='the input label to align')
parser.add_argument('--paraformer',
action='store_true',
help='whether to use the best chinese model')
args = parser.parse_args()
return args


def main():
args = get_args()
model = load_model(args.language, args.model_dir)

if args.paraformer:
model = load_paraformer(args.language, args.model_dir)
else:
model = load_model(args.language, args.model_dir)
if args.align:
result = model.align(args.audio_file, args.label)
else:
Expand Down
Loading