Skip to content

Commit

Permalink
add '--write_json' option to narabas
Browse files Browse the repository at this point in the history
  • Loading branch information
ohshima-axell committed Apr 10, 2024
1 parent 093fdca commit 2e96e58
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions audio_processing/narabas/narabas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import time
from typing import Union
import json

import ailia # noqa: E402
import numpy as np
Expand Down Expand Up @@ -43,6 +44,11 @@
help="sample rate",
default=16000,
)
parser.add_argument(
'-w', '--write_json',
action='store_true',
help='Flag to output results to json file.'
)
args = update_parser(parser)


Expand Down Expand Up @@ -125,6 +131,13 @@ def infer(net: Union[ailia.Net, onnxruntime.InferenceSession]):
for (start, end, phoneme) in segments:
logger.info(f"{start:.3f} {end:.3f} {phoneme}")

if args.write_json:
result = []
for (start, end, phoneme) in segments:
result.append({"start": float(start), "end": float(end), "phoneme": phoneme})
with open("output.json", "w", encoding="utf-8") as f:
json.dump(result, f, indent=2)


if __name__ == "__main__":
# disable FP16
Expand Down

0 comments on commit 2e96e58

Please sign in to comment.