Replacing Spoken Punctuation with Actual Punctuation Characters

When I dictate text I say something like this:

quote this is what I'm telling you comma quote said Sally period new line

which I want to appear in the finished text like this:

"This is what I'm telling you," said Sally.\n

Most of this I'm achieving through a transcription service called otter.ai, but the service does not handle spoken punctuation at all. (It actually doesn't handle much, but it does allow me to upload an audio file which it transcribes to text, which I then download into Scrivener, my word processor, where I massage it into a usable first draft.)

What I'd like KM to do is scan through my selected text and replace the spoken punctuation with the actual punctuation characters. I recognize that "new line" is a bit of a special case, but I see that KM allows me to run a Perl script, which should certainly be able to handle it. But my Perl is 20 years rusty, so I'm hoping someone here can help me out with this.

Anyone?

Maybe this will get you started.
I had to change your use of "quote" to "open quote" and "close quote" to properly handle the space before/after the word.
Also note in the PunctList there is a SPACE before most of the words.
It is a TAB delimited list.


Example Output

image


MACRO:   Replace Punctuation Words with Actual Punctuation [Example]


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/d/8/d802a6432f237ad81e8bc38647da0b5508f8ec21.kmmacros">Replace Punctuation Words with Actual Punctuation [Example].kmmacros</a> (6.3 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---



![image|479x1991](upload://kWH3IdBmx0dgWdoMLhHDrT6SnRz.png)

---

### Questions?

That looks pretty good! I see what you mean by the difference between open quote and close quote. I also see how to add punctuation characters such as colon ( : ) semicolon ( ; ) and exclamation mark ( ! ), and also for when I say exclamation point instead of exclamation mark. And so on.

I think I can figure out how to change the input so that it used the currently selected text instead of having to type into the variable as you did in your demo, and also how to output the resulting string in place of the currently selected text (I've been playing around with some other examples and learning from them.)

So thank you for your assistance! This is a big help!

1 Like

I had a stab at approaching this task, as I was hoping to eliminate the need to discriminate between opening and closing quotes and the need to be mindful of whitespace in declaring the punctuation. I'm also a big fan of utilising dictionaries, and though you and others may have differing opinions on this, I feel a dictionary lends itself quite nicely to this situation.

To this end, I also uploaded a macro to the forum library that aids in the creation and modification of a dictionary. One of the drawbacks in Keyboard Maestro that likely stops people from using dictionaries as much as they otherwise might is the lack of suitable tools in-house for manipulating them. The Create Dictionary macro simplifies one aspect of this, and below is the input that I used to create the dictionary of punctuation that the macro I'm posting here uses:

Punctuation {
	comma: ,
	period: .
	question mark: ?
	new line: \\n
	new paragraph: \\n\\n
	quote: "
	colon: :
	semicolon: ;
	hyphen: -
	dash: -
	slash: /
	open brackets: (
	close brackets: )
}

The Macro:


image  Replace Punctuation Literals.kmmacros (19.5 KB)


Note: I tested the macro on the following piece of source text:

this is my first sentence period the second one is quote so much more exciting comma quote if you can believe that period new paragraph quote this is my first sentence quote was what I wrote initially. quote this is my first sentence quote would be a lie if stated here in any context.

I included a variety of instances where quotes might appear in various differing contexts, such as at the start or middle of a sentence, and with or without punctuation at the end of the quote.

Although I included additional punctuation characters within the dictionary declaration, I didn't make use of them during testing; most notably, parentheses will not currently format correctly, but the principle for these will be identical to that of quotes.

1 Like