{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api.toneperfect.app/capsule/compact.schema.json",
  "title": "toneperfect.compact.v1",
  "type": "object",
  "required": [
    "schema",
    "id",
    "assessable",
    "reason",
    "locale",
    "task",
    "model_version",
    "scores",
    "words",
    "warnings",
    "billing"
  ],
  "properties": {
    "schema": {
      "const": "toneperfect.compact.v1"
    },
    "id": {
      "type": "string"
    },
    "assessable": {
      "type": "boolean"
    },
    "reason": {
      "type": [
        "string",
        "null"
      ]
    },
    "locale": {
      "type": [
        "string",
        "null"
      ]
    },
    "task": {
      "type": [
        "string",
        "null"
      ]
    },
    "model_version": {
      "type": [
        "string",
        "null"
      ]
    },
    "scores": {
      "type": "object",
      "required": [
        "overall",
        "pronunciation",
        "initial",
        "final",
        "tone",
        "fluency",
        "rhythm",
        "completeness"
      ],
      "properties": {
        "overall": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "pronunciation": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "initial": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "final": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "tone": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "fluency": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "rhythm": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "completeness": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        }
      }
    },
    "words": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "text",
          "pinyin",
          "score",
          "start_ms",
          "end_ms",
          "decision",
          "units"
        ],
        "properties": {
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "pinyin": {
            "type": [
              "string",
              "null"
            ]
          },
          "score": {
            "type": [
              "number",
              "null"
            ]
          },
          "start_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "end_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "decision": {
            "type": [
              "string",
              "null"
            ]
          },
          "units": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "dimension",
                "expected",
                "heard",
                "score",
                "decision"
              ],
              "properties": {
                "dimension": {
                  "type": "string",
                  "description": "initial, final or tone for zh-CN; phoneme otherwise"
                },
                "expected": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "heard": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "score": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "decision": {
                  "enum": [
                    "review",
                    "uncertain",
                    "no_correction",
                    "unassessable",
                    "partial",
                    "legacy_correction",
                    null
                  ]
                }
              }
            }
          }
        }
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "billing": {
      "type": "object",
      "required": [
        "credits",
        "balance_credits"
      ],
      "properties": {
        "credits": {
          "type": "integer",
          "minimum": 0
        },
        "balance_credits": {
          "type": "integer"
        },
        "free_credits": {
          "type": "integer"
        },
        "source": {
          "enum": [
            "free",
            "plan"
          ]
        },
        "credits_waived": {
          "type": "integer"
        }
      }
    }
  }
}