8000 Add `--out-file` in transcribe.py · GorSlawa/ffmpeg-python@dc531d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc531d1

Browse files
committed
Add --out-file in transcribe.py
1 parent 4bb2fc4 commit dc531d1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

examples/transcribe.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import loggi 8000 ng
1111
import subprocess
1212
import sys
13-
import IPython
1413

1514

1615
logging.basicConfig(level=logging.INFO, format='%(message)s')
@@ -20,6 +19,8 @@
2019

2120
parser = argparse.ArgumentParser(description='Convert speech audio to text using Google Speech API')
2221
parser.add_argument('in_filename', help='Input filename (`-` for stdin)')
22+
parser.add_argument('--out-file', type=argparse.FileType('w'), default='-',
23+
help='Output filename (defaults to stdout)')
2324
parser.add_argument('--timing', action='store_true', help='Include timing info')
2425

2526

@@ -53,12 +54,12 @@ def get_transcripts(audio_data, include_timing_info=False):
5354
return client.recognize(config, audio)
5455

5556

56-
def transcribe(in_filename, include_timing_info=False):
57+
def transcribe(in_filename, out_file=sys.stdout, include_timing_info=False):
5758
audio_data = decode_audio(in_filename)
5859
response = get_transcripts(audio_data, include_timing_info)
59-
print(MessageToJson(response, sort_keys=True))
60+
out_file.write(MessageToJson(response, sort_keys=True).encode('utf-8'))
6061

6162

6263
if __name__ == '__main__':
6364
args = parser.parse_args()
64-
transcribe(args.in_filename, args.timing)
65+
transcribe(args.in_filename, args.out_file, args.timing)

0 commit comments

Comments
 (0)
0