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

Added file-saving option for live transcription. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions transcribe_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def main():
parser.add_argument("--phrase_timeout", default=3,
help="How much empty space between recordings before we "
"consider it a new line in the transcription.", type=float)
parser.add_argument("--output_file", default=None,
help="Output file path for transcriptions.", type=str) # New argument
if 'linux' in platform:
parser.add_argument("--default_microphone", default='pulse',
help="Default microphone name for SpeechRecognition. "
Expand Down Expand Up @@ -135,6 +137,12 @@ def record_callback(_, audio:sr.AudioData) -> None:
os.system('cls' if os.name=='nt' else 'clear')
for line in transcription:
print(line)

# Write to output file if one was provided
if args.output_file:
with open(args.output_file, 'a') as f:
f.write(line + '\n')

# Flush stdout.
print('', end='', flush=True)

Expand All @@ -146,6 +154,9 @@ def record_callback(_, audio:sr.AudioData) -> None:
print("\n\nTranscription:")
for line in transcription:
print(line)
if args.output_file:
with open(args.output_file, 'a') as f:
f.write(line + '\n')


if __name__ == "__main__":
Expand Down