Skip to main content
Text-to-Speech

Convert LaTeX formulas to speech (Chinese language only)

Speak math formulas aloud

CosyVoice converts mathematical formulas embedded in text to natural speech for audiobooks, online education, and other audio content in mathematics and physics.
This feature only supports Chinese. Formulas may not be pronounced correctly in other languages. Pronunciation examples in this guide are English translations and do not represent actual synthesis performance.

Steps

Wrap the formulas in your text with specific separators, and then call the speech synthesis API.
1

Mark formulas with separators

Wrap formulas with any of these separators (all produce identical results):
  • $...$
  • $$...$$
  • \(...\)
  • \[...\]
Example:
Here is the quadratic formula: $x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$. Calculate carefully.
2

Call the API to request speech synthesis

Call the speech synthesis API with your marked formulas. In JSON or string literals, the backslash (\) is an escape character — write it as \\.Example call (in Python):
# coding=utf-8

import os
import dashscope
from dashscope.audio.tts_v2 import *

# Set your API key (format: sk-xxx). If not set as env var, uncomment the next line:
# dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')

dashscope.base_websocket_api_url='wss://dashscope-intl.aliyuncs.com/api-ws/v1/inference'

# Model
model = "cosyvoice-v3-flash"
# Voice (must be compatible with your model version)
#   cosyvoice-v3-flash/plus: longanyang, etc.
voice = "longanyang"

# Instantiate synthesizer with model and voice
synthesizer = SpeechSynthesizer(model=model, voice=voice)
# Send text and get binary audio
audio = synthesizer.call("This is the quadratic formula: $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$. Calculate it carefully.")
# First request includes WebSocket connection setup time
print('[Metric] requestId: {}, first-package delay: {} ms'.format(
  synthesizer.get_last_request_id(),
  synthesizer.get_first_package_delay()))

# Save audio to a local file
with open('output.mp3', 'wb') as f:
  f.write(audio)

Supported tags and symbols

The currently supported tags and symbols are listed below.

Basic mathematics

Tag or symbolFunctionFormula content exampleFormula input examplePronunciation
+Add2 + 3 = 5$2 + 3 = 5$Two plus three equals five
-Subtract3 - 2 = 1$3 - 2 = 1$Three minus two equals one
\pmPlus or minus / Positive or negative\pm 1 \pm 2$\pm 1\pm 2$Plus or minus one, plus or minus two
\timesMultiply2 \times 3 = 6$2 \times 3 = 6$Two times three equals six
×Multiply2 × 3 = 6$$2 × 3 = 6$$Two times three equals six
*Multiply2 * 3 = 6\(2 * 3 = 6\)Two times three equals six
\divDivide6\div2=3\[6\div2=3\]Six divided by two equals three
÷Divide6÷2=3$6÷2=3$Six divided by two equals three
/Divide6/2=3$6/2=3$Six divided by two equals three
=Equals3+5=8$3+5=8$Three plus five equals eight
<Less than1< 2$1< 2$One is less than two
Less than or equal to3≤5$3≤5$Three is less than or equal to five
<=Less than or equal to3<=5$3<=5$Three is less than or equal to five
\leqLess than or equal to3\leq5$3\leq 5$Three is less than or equal to five
\leLess than or equal to3\le5$3\le 5$Three is less than or equal to five
\leqqLess than or equal to3\leqq5$3\leqq 5$Three is less than or equal to five
\leqslantLess than or equal to3\leqslant5$3\leqslant 5$Three is less than or equal to five
>Greater than2>1$2>1$Two is greater than one
Greater than or equal to5≥3$5≥3$Five is greater than or equal to three
>=Greater than or equal to5>=3$5>=3$Five is greater than or equal to three
\geqGreater than or equal to5\geq3$5\geq 3$Five is greater than or equal to three
\geGreater than or equal to5\ge3$5\ge 3$Five is greater than or equal to three
\geqqGreater than or equal to5\geqq3$5\geqq 3$Five is greater than or equal to three
\geqslantGreater than or equal to5\geqslant3$5\geqslant 3$Five is greater than or equal to three
\fracFraction2\frac3$\frac {2}{3}$Two-thirds
^Power2^1$2^{1}$Two to the first power
\sqrtRoot\sqrt{9} = 3$\sqrt {9} = 3$The square root of nine equals three
\sqrtRoot\sqrt[3]{8} = 2$\sqrt[3]{8} = 2$The cube root of eight equals two
%Percentage5\%$5\%$Five percent
|Absolute value∣3∣=3$|3| =3$The absolute value of three equals three
\vertAbsolute value3\vert=3$\vert 3\vert =3$The absolute value of three equals three
\lgLogarithmlg {10}$\lg {10}$log ten
\logLogarithm\log{5}$\log{5}$log five
\lnNatural logarithm\lnX$ln {10}$LN 10
!Factorial5!$5!$Five factorial
()Parentheses(2+1)$(2+1)$Two plus one in parentheses
\{ \}Braces\{2+1\}$\{2+1\}$Open brace two plus one close brace

Special mathematical symbols

Tag or symbolTransformFormula content exampleFormula input examplePronunciation
\alphaalpha\alpha$\alpha$alpha
\Alphaalpha\Alpha$\Alpha$alpha
\betabeta\beta$\beta$beta
\Betabeta\Beta$\Beta$beta
\gammagamma\gamma$\gamma$gamma
\Gammagamma\Gamma$\Gamma$gamma
\deltadelta\delta$\delta$delta
\Deltadelta\Delta$\Delta$delta
\inftyinfinity (Chinese)\infty$\infty$Infinity
infty (English)$∞$Infinity

Geometry

Tag or symbolFunctionFormula content exampleFormula input examplePronunciation
\piPi\pi=3.14159$\pi =3.14159$Pi equals 3.14159
\sinTrigonometric function\sin 30^\circ=\frac{1}{2}$\sin 30^\circ =\frac {1}{2}$The sine of 30 degrees equals 1/2
\cosTrigonometric function\cos 30^\circ=\frac{\sqrt{2}}{2}$\cos 30^\circ =\frac {\sqrt {2}}{2}$The cosine of 30 degrees equals the square root of two over two
\tanTrigonometric function\tan 30^\circ=\frac{\sin 30^\circ}{\cos 30^\circ}$\tan 30^\circ =\frac {\sin 30^\circ}{\cos 30^\circ}$The tangent of 30 degrees equals the sine of 30 degrees over the cosine of 30 degrees
\cscTrigonometric function\csc A$\csc A$cosecant A
\secTrigonometric function\sec A$\sec A$secant A
\cotTrigonometric function\cot A$\cot A$cotangent A
\angleAngle\angle AB$\angle AB$Angle AB
Angle∠AB$∠AB$Angle AB
^\circDegree∠AB = 30^\circ$∠AB = 30^\circ$Angle AB equals 30 degrees
\odotCircle\odot$\odot$Circle
\overset\frownArc\overset\frown {BC}$\overset\frown {BC}$Arc BC
\rm{Rt}Right angle\because \rm{Rt}\triangle ABC$\because \rm{Rt}\triangle ABC$Because triangle ABC is a right triangle
\mathrm{Rt}Right angle\therefore AB \perp BC$\therefore AB \perp BC$Therefore, AB is perpendicular to BC
\triangleTriangle\triangle ABC$\triangle ABC$Triangle ABC
Triangle△ABC$△ABC$Triangle ABC
\parallelogramParallelogram\parallelogram ABCD$\parallelogram ABCD$Parallelogram ABCD
\perpPerpendicularAB \perp BC$AB \perp BC$AB is perpendicular to BC
\botPerpendicularAB \bot BC$AB \bot BC$AB is perpendicular to BC
PerpendicularAB ⊥ BC$AB ⊥ BC$AB is perpendicular to BC
\parallelParallelA\parallel B$A\parallel B$A is parallel to B
\equalparallelParallel and equal toA\equalparallel B$A\equalparallel B$A is parallel and equal to B
\congCongruent△ABC\cong△DEF$△ABC\cong△DEF$Triangle ABC is congruent to triangle DEF

Conditions

Tag or symbolFunctionFormula content exampleFormula input examplePronunciation
\impliesImplies\implies 1+1=2$\implies 1+1=2$This implies that one plus one equals two
\iffEquivalent top\iffq$p\iffq$p is equivalent to q
\becauseBecause\because a = b \therefore b=a$\because a = b \therefore b=a$Because a equals b, b equals a
\thereforeTherefore\because a = b \therefore b=a$\because a = b \therefore b=a$Because a equals b, b equals a

Units

Units must be wrapped with \unit, \quantity, \mathit, \mathrm, or \rm tags (such as \unit{cm}).
Tag or symbolPronunciationFormula content exampleFormula input exampleExample pronunciation
mmmillimeter5\quantity{mm}$5\quantity{mm}$5 millimeters
cmcentimeter5\quantity{cm}$5\quantity{cm}$5 centimeters
dmdecimeter5\quantity{dm}$5\quantity{dm}$5 decimeters
mmeter5\quantity{m}$5\quantity{m}$5 meters
kmkilometer5\quantity{km}$5\quantity{km}$5 kilometers
ggram5\quantity{g}$5\quantity{g}$5 grams
kgkilogram5\quantity{kg}$5\quantity{kg}$5 kilograms
tton5\quantity{t}$5\quantity{t}$5 tons
mm^2square millimeter5\quantity{mm^2}$5\quantity{mm^2}$5 square millimeters
cm^2square centimeter5\quantity{cm^2}$5\quantity{cm^2}$5 square centimeters
dm^2square decimeter5\quantity{dm^2}$5\quantity{dm^2}$5 square decimeters
m^2square meter5\quantity{m^2}$5\quantity{m^2}$5 square meters
km^2square kilometer5\quantity{km^2}$5\quantity{km^2}$5 square kilometers
mm^3cubic millimeter5\quantity{mm^3}$5\quantity{mm^3}$5 cubic millimeters
cm^3cubic centimeter5\quantity{cm^3}$5\quantity{cm^3}$5 cubic centimeters
dm^3cubic decimeter5\quantity{dm^3}$5\quantity{dm^3}$5 cubic decimeters
m^3cubic meter5\quantity{m^3}$5\quantity{m^3}$5 cubic meters
km^3cubic kilometer5\quantity{km^3}$5\quantity{km^3}$5 cubic kilometers
mlmilliliter5\quantity{ml}$5\quantity{ml}$5 milliliters
ssecond5\quantity{s}$5\quantity{s}$5 seconds
minminute5\quantity{min}$5\quantity{min}$5 minutes
hhour5\quantity{h}$5\quantity{h}$5 hours
km/hkilometers per hour5\quantity{km/h}$5\quantity{km/h}$5 kilometers per hour
g/lgrams per liter5\quantity{g/l}$5\quantity{g/l}$5 grams per liter

Limitations

  • Chinese only: Other languages are not supported
  • Content limits:
    • Use only the tags and symbols in Supported tags and symbols
    • Markdown math blocks (```math ... ```) are not supported
    • Include only formulas within separators - other content may cause inaccurate synthesis
  • Compatible models: cosyvoice-v3-flash, cosyvoice-v3-plus

FAQ

Why is the formula I entered not read?

  1. Separators: Confirm the formula is wrapped in $...$, $$...$$, \(...\), or \[...\]
  2. Formula complexity: Ensure the formula uses only supported tags and symbols
  3. Escape characters: Confirm backslashes (\) are escaped as \\ in API requests

How do I handle backslash (\) in my code?

The backslash (\) is an escape character in string literals and JSON. Escape it as \\. Example: write \frac as \\frac in Python, Java, JavaScript, and similar languages.