Skip to content

Instantly share code, notes, and snippets.

@srcecde
Created November 7, 2019 15:57
Show Gist options
  • Save srcecde/45ab02358491f6e140f73a8a83367ead to your computer and use it in GitHub Desktop.
Save srcecde/45ab02358491f6e140f73a8a83367ead to your computer and use it in GitHub Desktop.
#-*- coding: utf-8 -*-
__author__ = "Chirag Rathod (Srce Cde)"
__license__ = "MIT"
__email__ = "[email protected]"
__maintainer__ = "Chirag Rathod (Srce Cde)"
import json
with open("sample.json", "r") as f:
json_load = json.load(f)
channels = json_load["results"]["channel_labels"]
items = json_load["results"]["items"]
speaker_text = []
flag = False
temp = None
for word in items:
with open("transcribe.txt", "a") as f:
for seg in channels["channels"]:
for seg_item in seg["items"]:
# print(word["type"])
if "start_time" in seg_item and word["type"] != "punctuation":
if word["end_time"] == seg_item["end_time"] and word["start_time"] == seg_item["start_time"]:
# if word["alternatives"][0]["content"]:
if temp != seg["channel_label"]:
f.write("{} : ".format(seg["channel_label"]))
speaker_text.append(word["alternatives"][0]["content"])
flag = True
temp = seg["channel_label"]
else:
speaker_text.append(word["alternatives"][0]["content"])
flag = True
if word["type"] == "punctuation":
f.write(word["alternatives"][0]["content"])
f.write(" {}".format(' '.join(speaker_text)))
speaker_text = []
# sample output
"""
ch_1 : Good afternoon. You know, factories. ch_0 : Yes. Hi. I was gonna see if Travis weekends available. ch_1 : Uh, he is not in today. He'll be back Monday. ch_0 : Alright, I'll try back down. Thanks. ch_1 : Thank you. ch_0 : Thank you.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment