Skip to content

Commit

Permalink
Add file flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tfkalk committed Jul 14, 2024
1 parent 990d674 commit 9ed490b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 14 additions & 15 deletions MultiSpeakerTranscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@
import sys
import argparse

API_KEY = os.getenv("MULTISPEAKER_API")
if API_KEY is None:
print("You are missing a value at $ASSEMBLY_AI_API. Set your API key and run again")
sys.exit(3)

# Take in an argument of the file
parser = argparse.ArgumentParser("MultispeakerTranscribe")
parser.add_argument("audio", help="The filename of an audio file to be transcribed.")
args = parser.parse_args()

transcribe_file(args.audio)


# Methods
def transcribe_file(file):
# Chop off extension from file
filename = os.path.splitext(file)[0]

try:
f = open("./Transcripts/" + filename + ".txt", "x")
except FileExistsError:
Expand All @@ -37,7 +24,7 @@ def transcribe_file(file):
print("Proceeding to transcribe the file.")

transcript = transcriber.transcribe(
"./Interviews/"+file,
file,
config=config
)

Expand All @@ -52,3 +39,15 @@ def transcribe_file(file):
# Delete the transcript so the only copy is local.
print("Proceeding to transcript id: " + transcript.id)
transcript.delete_by_id(transcript.id)

API_KEY = os.getenv("MULTISPEAKER_API")
if API_KEY is None:
print("You are missing a value at $ASSEMBLY_AI_API. Set your API key and run again")
sys.exit(3)

# Take in an argument of the file
parser = argparse.ArgumentParser("MultispeakerTranscribe")
parser.add_argument("--file", dest='audio', help="The path of the audio file to be transcribed.")
args = parser.parse_args()

transcribe_file(args.audio)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You'll need to run `pip3 install assemblyai` (should work for macOS users) or `p

When running MultispeakerTranscription, it currently expects to have an `Interviews` directory and a `Transcripts` directory in the same directory where it is being run. For example, if you have downloaded this file to `~/Downloads`, there should be `~/Downloads/Interviews` and `~/Downloads/Transcripts`. Then you can run this with `python3 MultiSpeakerTranscriber.py "<filename>"`. You only need to provide the file name. I recommend including quotation marks around to avoid splitting.

Example: `python3 MultiSpeakerTranscriber.py "Montgomery Ward 1873-11-02.m4a"`
Example: `python3 MultiSpeakerTranscriber.py --file "Montgomery Ward 1873-11-02.m4a"`

### What is this $SHELL
*Note: This guide is currently Unix-centric*
Expand Down

0 comments on commit 9ed490b

Please sign in to comment.