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)
def test_append_before_ext_extension_3_dots(): assert append_before_ext('cleansio.w.a.v', '-acc') == 'cleansio.w.a-acc.v'
def test_append_before_ext_extension_1_dot(): assert append_before_ext('cleansio.wav', '-acc') == 'cleansio-acc.wav'
def test_append_before_ext_no_extension(): assert append_before_ext('cleansio', 'extra') == 'cleansioextra'
def test_append_before_ext_no_extension_empty_string(): assert append_before_ext('cleansio', '') == 'cleansio'
def test_append_before_ext_empty_addition(): assert append_before_ext('cleansio.wav', '') == 'cleansio.wav'
def test_append_before_ext_empty_string(): assert append_before_ext('', '-acc') == '-acc'
def test_append_before_ext_empty_string_empty_addition(): assert append_before_ext('', '') == ''
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)
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')
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