Skip to content
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

Receiving and storing text with Python #379

Closed
MathewYaldo opened this issue Sep 16, 2023 · 3 comments
Closed

Receiving and storing text with Python #379

MathewYaldo opened this issue Sep 16, 2023 · 3 comments

Comments

@MathewYaldo
Copy link

I understand that this tool is to primarily create custom commands, but is it also possible to just receive the speech output and store it with Python?

I want to be able to talk into a microphone and process or store all of the speech with Python, but I couldn’t find anything regarding this on the Dragon website, so I was wondering if this tool might be able to help with something like that? The primarily intention would be not to use the text for commands but just to transcribe all the speech and store it.

@drmfinlay
Copy link
Member

drmfinlay commented Sep 17, 2023

Hello Mathew,

Thank you for opening this issue.

Dragonfly can be used to transcribe speech into text for you. Try placing the code below into a new file _transcriber.py in the Natlink MacroSystem folder. You'll have to toggle the microphone to load the module. Your speech should be transcribed into the dfly transcript.txt file in your home folder.

import os
from dragonfly import CompoundRule, Dictation, Grammar

class TranscriberRule(CompoundRule):
    spec = "<text>"
    extras = [Dictation("text")]
    out_dir = os.path.expanduser('~')
    out_file = os.path.join(out_dir, "dfly transcript.txt")

    def _process_recognition(self, node, extras):
        # Retrieve the recognized text and format it.
        text = extras.get("text").format()

        # Append the text to *out_file*.
        with open(self.out_file, "a") as f:
            f.write(text + "\n")


# Create a new Grammar object and add a TranscriberRule instance to it.
grammar = Grammar("Transcriber grammar")
grammar.add_rule(TranscriberRule())

# Load the grammar and set it as exclusive, meaning that the engine will
#  only recognize from this grammar (and any other exclusive grammar).
grammar.load()
grammar.set_exclusiveness(True)

# Unload function which will be called by natlink at unload time.
def unload():
    global grammar
    if grammar: grammar.unload()
    grammar = None

Dragon does ship with a transcription program, by the way. It is listed in the start menu as AutoTranscribe Folder Agent. Perhaps you missed it? It does require separate recording software, so it might not be what you want.

@MathewYaldo
Copy link
Author

@drmfinlay Thank you, this looks like what I was looking for. I just had a couple more questions regarding setting everything up. I have looked at #337 but I confused regarding what the right environment setup should be.

  • Will 64-bit python work, or should the 32-bit version continue to be used?
  • I cannot install natlink through pip. It tells me that it does not exist, and when looking for it online, I can only find natlinkcore. Is this the same library? If so, what is the recommended python version as this requires python 3.9+.

I have also noticed that the docs at https://dragonfly2.readthedocs.io/en/latest/installation.html mention Python 2.7 32-bit and downloading some Natlink exe files through SourceForge. Should I try to follow this? Not sure if this would all work for Dragon 15 which is what I am on.

@LexiconCode
Copy link
Member

LexiconCode commented Sep 18, 2023

@MathewYaldo

I've written about how to use the new setup for natlink. Most of the documentation there applies to dragonfly except for the caster package requirements. You still have to utilize a 32 bit python environment. The new natlink installer handles it for you.
dictation-toolbox/Caster#911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants