Esempio n. 1
0
 def __transcribe_chunk(self, async_iter):
     """ Accesses Google Cloud Speech and print the lyrics for each chunk """
     frame_rate, encoding, file_path = async_iter
     accuracy_chunk_path = append_before_ext(file_path, '-accuracy')
     with open(accuracy_chunk_path, 'rb') as audio_content:
         content = audio_content.read()
     config = self.__get_config(encoding, frame_rate)
     audio = types.RecognitionAudio(content=content)
     return SpeechClient().recognize(config, audio)
Esempio n. 2
0
def test_append_before_ext_extension_3_dots():
    assert append_before_ext('cleansio.w.a.v', '-acc') == 'cleansio.w.a-acc.v'
Esempio n. 3
0
def test_append_before_ext_extension_1_dot():
    assert append_before_ext('cleansio.wav', '-acc') == 'cleansio-acc.wav'
Esempio n. 4
0
def test_append_before_ext_no_extension():
    assert append_before_ext('cleansio', 'extra') == 'cleansioextra'
Esempio n. 5
0
def test_append_before_ext_no_extension_empty_string():
    assert append_before_ext('cleansio', '') == 'cleansio'
Esempio n. 6
0
def test_append_before_ext_empty_addition():
    assert append_before_ext('cleansio.wav', '') == 'cleansio.wav'
Esempio n. 7
0
def test_append_before_ext_empty_string():
    assert append_before_ext('', '-acc') == '-acc'
Esempio n. 8
0
def test_append_before_ext_empty_string_empty_addition():
    assert append_before_ext('', '') == ''
Esempio n. 9
0
 def __transcribe_chunks(self, frame_rate, encoding, file_path):
     file_paths = [file_path, append_before_ext(file_path, '-overlapping')]
     async_iter = zip(repeat(frame_rate), repeat(encoding), file_paths)
     transcripts = ThreadPool(2).map(self.__transcribe_chunk, async_iter)
     return self.__combine_transcripts(transcripts)
Esempio n. 10
0
 def __create_accuracy_chunk(self, chunk, file_path):
     accuracy_chunk_file_path = append_before_ext(file_path, '-accuracy')
     accuracy_chunk = improve_accuracy(chunk)
     convert_and_write_chunk(accuracy_chunk, accuracy_chunk_file_path, 'wav')
Esempio n. 11
0
 def __create_overlapping_chunk(self, chunk1, chunk2, file_path):
     overlapping_chunk = chunk1[2500:] + chunk2[:2500]
     overlapping_path = append_before_ext(file_path, '-overlapping')
     convert_and_write_chunk(overlapping_chunk, overlapping_path, 'wav')
     self.__update_env_chunks_list(overlapping_path)
     return overlapping_chunk, overlapping_path