-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter out bad stitched samples by checking the speech to text transc…
…ription (#72) * sphinx keyword detector * support audio sample verification with keyword detection * fix incorrect name
- Loading branch information
Showing
28 changed files
with
193 additions
and
60 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
|
||
from pocketsphinx import AudioFile | ||
|
||
|
||
class SphinxKeywordDetector(): | ||
def __init__(self, target_transcription, threshold=1e-20, verbose=False): | ||
self.target_transcription = target_transcription | ||
self.verbose = verbose | ||
self.kws_config = { | ||
'verbose': self.verbose, | ||
'keyphrase': self.target_transcription, | ||
'kws_threshold': threshold, | ||
'lm': False, | ||
} | ||
|
||
def detect(self, file_name): | ||
|
||
kws_results = [] | ||
|
||
self.kws_config['audio_file'] = file_name | ||
audio = AudioFile(**self.kws_config) | ||
|
||
for phrase in audio: | ||
result = phrase.segments(detailed=True) | ||
|
||
# TODO:: confirm that when multiple keywords are detected, every detection is valid | ||
if len(result) == 1: | ||
start_time = result[0][2] * 10 | ||
end_time = result[0][3] * 10 | ||
if self.verbose: | ||
print('%4sms ~ %4sms' % (start_time, end_time)) | ||
kws_results.append((start_time, end_time)) | ||
|
||
return kws_results |
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,5 +1,6 @@ | ||
openpyxl | ||
pocketsphinx==0.1.15 | ||
praat-textgrids==1.3.1 | ||
webrtcvad==2.0.10 | ||
pytest | ||
pre-commit | ||
pytest | ||
webrtcvad==2.0.10 |
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
Binary file not shown.
Binary file not shown.
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 @@ | ||
stitched | ||
stitched_dataset |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,28 @@ | ||
import unittest | ||
|
||
from howl.utils.sphinx_keyword_detector import SphinxKeywordDetector | ||
|
||
|
||
class TestSphinxKeywordDetector(unittest.TestCase): | ||
|
||
def test_detect(self): | ||
"""test word detection from an audio file | ||
""" | ||
|
||
hello_world_file = "test/test_data/sphinx_keyword_detector/hello_world.wav" | ||
hello_extractor = SphinxKeywordDetector("hello") | ||
self.assertTrue(len(hello_extractor.detect(hello_world_file)) > 0) | ||
world_extractor = SphinxKeywordDetector("world") | ||
self.assertTrue(len(world_extractor.detect(hello_world_file)) > 0) | ||
|
||
hey_fire_fox_file = "test/test_data/sphinx_keyword_detector/hey_fire_fox.wav" | ||
hey_extractor = SphinxKeywordDetector("hey") | ||
self.assertTrue(len(hey_extractor.detect(hey_fire_fox_file)) > 0) | ||
fire_extractor = SphinxKeywordDetector("fire") | ||
self.assertTrue(len(fire_extractor.detect(hey_fire_fox_file)) > 0) | ||
fox_extractor = SphinxKeywordDetector("fox") | ||
self.assertTrue(len(fox_extractor.detect(hey_fire_fox_file)) > 0) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.