sveinbjornt / hear

Command line speech recognition and transcription for macOS
https://sveinbjorn.org/hear
BSD 3-Clause "New" or "Revised" License
332 stars 20 forks source link

Dealing With ANSI Escape Sequences #21

Closed harrisoncramer closed 1 year ago

harrisoncramer commented 1 year ago

Hello, I'm hoping to use this tool as a way to have speech-to-text in the terminal and to then send the query as a JSON payload to the ChatGPT API.

The little Bash script looks like this:

Screenshot 2023-04-08 at 12 21 49 PM

The problem that I'm encountering is that the JSON is malformed, and ends up looking like this:

{ "model": "text-davinci-003", "prompt": "\u001b[2K\rTell\u001b[2K\rTell me a\u001b[2K\rTell me a joke\u001b[2K\rTell me a joke send", "max_tokens": "100", "temperature": "0.5" }

Do you know why this is the case, and how I might resolve this so that only the full final output of hear is used? From what I can tell by cat-ing out the /tmp/voice.txt file, it does contain just the prompt. I'm confused on why the includes these extra ANSI escape characters.

harrisoncramer commented 1 year ago

Realized that I needed to use mac2unix to convert the file!

sveinbjornt commented 1 year ago

You don't want to use single-line mode (-m).