-
Notifications
You must be signed in to change notification settings - Fork 60
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
[ros_speech_recognition] Add vosk engine #462
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2199382
[ros_speech_recognition] Update dependencies
nakane11 e6956bc
[ros_speech_recognition] Use vosk engine
nakane11 7f1d084
[ros_speech_recognition] transform vosk result
nakane11 46bd2a2
[ros_speech_recognition] add vosk_model_path description to README
nakane11 a81d301
[ros_speech_recognition] Install vosk models
nakane11 e181b80
[ros_speech_recognition] Use installed vosk model
nakane11 0952c9f
Merge branch 'master' into vosk
k-okada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
SpeechRecognition==3.8.1 | ||
SpeechRecognition==3.9.0 | ||
vosk==0.3.45 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import multiprocessing | ||
|
||
import jsk_data | ||
|
||
|
||
def download_data(*args, **kwargs): | ||
p = multiprocessing.Process( | ||
target=jsk_data.download_data, | ||
args=args, | ||
kwargs=kwargs) | ||
p.start() | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-v', '--verbose', dest='quiet', action='store_false') | ||
args = parser.parse_args() | ||
quiet = args.quiet | ||
|
||
PKG = 'ros_speech_recognition' | ||
|
||
download_data( | ||
pkg_name=PKG, | ||
path='trained_data/vosk-model-small-ja-0.22.zip', | ||
url='https://alphacephei.com/vosk/models/vosk-model-small-ja-0.22.zip', # NOQA | ||
md5='0e3163dd62dfb0d823353718ac3cbf79', | ||
extract=True, | ||
quiet=quiet, | ||
) | ||
|
||
download_data( | ||
pkg_name=PKG, | ||
path='trained_data/vosk-model-small-en-us-0.15.zip', | ||
url='https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip', # NOQA | ||
md5='09ab50ccd62b674cbaa231b825f9c1cb', | ||
extract=True, | ||
quiet=quiet, | ||
) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
ros_speech_recognition/src/ros_speech_recognition/recognize_vosk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# file to override recognize_vosk | ||
# we need this to use vosk model anywhere | ||
|
||
from speech_recognition import AudioData | ||
from ros_speech_recognition.recognize_google_cloud import RecognizerEx | ||
from vosk import Model, KaldiRecognizer | ||
import json | ||
import os.path as osp | ||
import rospkg | ||
import rospy | ||
|
||
def recognize_vosk(self, audio_data, model_path=None, language='en-US'): | ||
|
||
assert isinstance(audio_data, AudioData), "Data must be audio data" | ||
|
||
if not hasattr(self, 'vosk_model'): | ||
if model_path is None: | ||
PKG = 'ros_speech_recognition' | ||
rp = rospkg.RosPack() | ||
data_path = osp.join(rp.get_path(PKG), 'trained_data') | ||
if language == 'en-US': | ||
model_path = osp.join(data_path, 'vosk-model-small-en-us-0.15') | ||
elif language == 'ja': | ||
model_path = osp.join(data_path, 'vosk-model-small-ja-0.22') | ||
else: | ||
rospy.logerr("Unsupported language: {0}.\n Please download the model from https://alphacephei.com/vosk/models and specify its path as 'vosk_model_path'.".format(language)) | ||
exit (1) | ||
nakane11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rospy.loginfo("Loading model from {}".format(model_path)) | ||
self.vosk_model = Model(model_path) | ||
rec = KaldiRecognizer(self.vosk_model, 16000); | ||
|
||
rec.AcceptWaveform(audio_data.get_raw_data(convert_rate=16000, convert_width=2)); | ||
finalRecognition = rec.FinalResult() | ||
text = json.loads(finalRecognition)['text'] | ||
return text | ||
|
||
RecognizerEx.recognize_vosk = recognize_vosk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very sorry for too late comment.
I just found that both
SpeechRecognition==3.9.0
andvosk
are not compatible with python 3.4, so indigo test will surely fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be ok to drop indigo support dependent on #471 discussion.