示例#1
0
 def record_speech(self):
     try:
         self.set_cursor_pos(0)
         self.clear()
         self.text_edit.setFocus()
         audio_interface = pyaudio.PyAudio()
         transcribed_input = transcribe(audio_interface)
         self.text_edit.setText(transcribed_input)
         transcribed_input
     except Exception:
         traceback.print_exc()
         modal.ModalMessageWindow(
             self.design_view.main_window, str(sys.exc_info()[1]), "Oops! Something went wrong!", modal.MSG_ERROR
         )
示例#2
0
def commands(arr, selector):
    """
    Commands supported by the CLI
    """
    if arr[0] == "exit" or arr[0] == "e":
        click.secho("\nGood bye!", fg="green", bold=True)
        click.clear()
        sys.exit()
    elif arr[0] == "help" or arr[0] == "h":
        help_output()
    elif arr[0] == "language" or arr[0] == "lang":
        SETTINGS["user"]["language"] = config_model_language(
            get_model_languages())
        SETTINGS["user"]["language_version"] = choose_version(
            get_language_versions(SETTINGS["user"]["language"]))
        update_settings("../config/user", SETTINGS["user"])
    elif arr[0] == "install" or arr[0] == "i":
        model_installer = Model_Installer()
        language = config_model_language(model_installer.get_languages())
        version = choose_version(model_installer.get_versions(language))
        model_installer.install(language, version)
    elif arr[0] == "record" or arr[0] == "r":
        # create audio interface and inform user that the output can be ignored
        audio_interface = pyaudio.PyAudio()
        click.echo(
            "\nIf you see warning messages above they can be ignored. It's caused by PyAudio"
            + " (used for micrpohone input) and cannot be removed.\n")
        click.echo("Recording, please speak...")
        transcribed_input = transcribe(audio_interface)
        audio_interface.terminate()
        ans = input(
            f"This is what I heard:\n    {transcribed_input}\nExecute? [Y/n]: "
        ).lower()
        if ans == "y" or ans == "yes" or ans == "":
            run_selector(transcribed_input, selector)
        else:
            click.echo("Canceled.")
    else:
        text = " ".join(map(str, arr))
        run_selector(text, selector)
示例#3
0
 def test_language_not_supported(self, user_with_non_supported_lang):
     """Test that an exception is raised when the user has a non-supported language"""
     with pytest.raises(LanguageNotSupportedError) as excinfo:
         transcribe(None)
     assert "not supported for the current language" in str(excinfo.value)
示例#4
0
 def helper():
     monkeypatch.setattr("lib.speech.transcribe.os.path.isfile",
                         mock_isfile)
     return transcribe(None)