All Products
Search
Document Center

Alibaba Cloud Model Studio:Dukungan CosyVoice untuk LaTeX (hanya bahasa Tiongkok)

Last Updated:Mar 04, 2026

Mengonversi teks yang berisi formula matematika kompleks menjadi ucapan yang lancar dan akurat merupakan tantangan dalam skenario seperti buku audio dan pembelajaran daring. CosyVoice mengurai formula yang tertanam dalam teks dan membacakannya secara alami. Fitur ini secara signifikan meningkatkan pengalaman mendengarkan konten pada mata pelajaran seperti matematika dan fisika.

Penting

Fitur ini hanya mendukung sintesis suara dalam bahasa Tiongkok. Formula mungkin tidak diucapkan dengan benar dalam bahasa lain. Semua contoh pengucapan dalam topik ini bersifat ilustratif dan tidak merepresentasikan kinerja aktual.

Prosedur

Bungkus formula dalam teks Anda dengan pemisah tertentu, lalu panggil API sintesis suara.

  1. Tandai formula dengan pemisah

    Bungkus formula dengan salah satu pemisah berikut agar sistem dapat mendeteksi dan menguraikannya.

    Pilihan pemisah tidak memengaruhi hasil sintesis. Anda dapat menggunakan format apa pun di bawah ini.

    • $...$

    • $$...$$

    • \(...\)

    • \[...\]

    Contoh:

    Berikut adalah rumus kuadrat: $x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$. Hitung dengan cermat.
  2. Panggil API untuk meminta sintesis suara

    Panggil API sintesis suara dengan teks yang berisi formula yang telah ditandai. Perhatikan bahwa dalam badan permintaan berformat JSON atau literal string, backslash (\) merupakan karakter escape. Oleh karena itu, Anda harus menuliskannya sebagai \\.

    Contoh pemanggilan (dalam Python):

    # coding=utf-8
    
    import os
    import dashscope
    from dashscope.audio.tts_v2 import *
    
    # Kunci API berbeda antara wilayah Singapura dan Beijing. Dapatkan kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    # Jika Anda belum menyetel variabel lingkungan, ganti baris berikut dengan Kunci API Model Studio Anda: dashscope.api_key = "sk-xxx"
    dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
    
    # URL ini digunakan untuk wilayah Singapura. Untuk wilayah Beijing, gunakan: wss://dashscope.aliyuncs.com/api-ws/v1/inference
    dashscope.base_websocket_api_url='wss://dashscope-intl.aliyuncs.com/api-ws/v1/inference'
    
    # Model
    model = "cosyvoice-v3-flash"
    # Voice
    #    Gunakan voice yang kompatibel dengan versi model Anda:
    #        cosyvoice-v3-flash/cosyvoice-v3-plus: gunakan voice seperti longanyang
    voice = "longanyang"
    
    # Buat instance SpeechSynthesizer dan teruskan model serta voice sebagai parameter permintaan
    synthesizer = SpeechSynthesizer(model=model, voice=voice)
    # Kirim teks untuk sintesis dan dapatkan audio biner
    audio = synthesizer.call("This is the quadratic formula: $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$. Calculate it carefully.")
    # Permintaan pertama akan membuat koneksi WebSocket, sehingga latensi paket pertama mencakup waktu penyiapan koneksi
    print('[Metric] requestId: {}, first-package latency: {} ms'.format(
        synthesizer.get_last_request_id(),
        synthesizer.get_first_package_delay()))
    
    # Simpan audio ke file lokal
    with open('output.mp3', 'wb') as f:
        f.write(audio)

Tag dan simbol yang didukung

Tabel berikut mencantumkan tag dan simbol yang saat ini didukung.

Matematika dasar

Tag atau simbol

Fungsi

Contoh isi formula

Contoh input formula

Pengucapan

+

Add

2 + 3 = 5

$2 + 3 = 5$

Two plus three equals five

-

Subtract

3 - 2 = 1

$3 - 2 = 1$

Three minus two equals one

\pm

Plus or minus

\pm 1 \pm 2

$\pm 1\pm 2$

Plus or minus one, plus or minus two

Positive or negative

\times

Multiply

2 \times 3 = 6

$2 \times 3 = 6$

Two times three equals six

×

2 × 3 = 6

$$2 × 3 = 6$$

*

2 * 3 = 6

\(2 * 3 = 6\)

\div

Divide

6\div2=3

\[6\div2=3\]

Six divided by two equals three

÷

6÷2=3

$6÷2=3$

/

6/2=3

$6/2=3$

=

Equals

3+5=8

$3+5=8$

Three plus five equals eight

<

Less than

1< 2

$1< 2$

One is less than two

Less than or equal to

3≤5

$3≤5$

Three is less than or equal to five

<=

3<=5

$3<=5$

\leq

3\leq5

$3\leq 5$

\le

3\le5

$3\le 5$

\leqq

3\leqq5

$3\leqq 5$

\leqslant

3\leqslant5

$3\leqslant 5$

>

Greater than

2>1

$2>1$

Two is greater than one

Greater than or equal to

5≥3

$5≥3$

Five is greater than or equal to three

>=

5>=3

$5>=3$

\geq

5\geq3

$5\geq 3$

\ge

5\ge3

$5\ge 3$

\geqq

5\geqq3

$5\geqq 3$

\geqslant

5\geqslant3

$5\geqslant 3$

\frac

Score

2\frac3

$\frac {2}{3}$

Two-thirds

^

Power

2^1

$2^{1}$

Two to the first power

\sqrt

Root

\sqrt{9} = 3

$\sqrt {9} = 3$

The square root of nine equals three

\sqrt[3]{8} = 2

$\sqrt[3]{8} = 2$

The cube root of eight equals two

\%

Percentage

5\%

$5\%$

Five percent

|

Absolute value

∣3∣=3

$|3| =3$

The absolute value of three equals three

\vert

3\vert=3

$\vert 3\vert =3$

The absolute value of three equals three

\lg

Logarithm

lg {10}

$\lg {10}$

log ten

\log

Logarithm

\log{5}

$\log{5}$

log five

\ln

Natural logarithm

\lnX

$ln {10}$

LN 10

!

Factorial

5!

$5!$

Five factorial

()

Parentheses

(2+1)

$(2+1)$

Two plus one in parethesises

\{ \}

$\{2+1\}$

Open brace two plus one close brace

Simbol matematika khusus

Tag atau simbol

Transform

Contoh isi formula

Contoh input formula

Pengucapan

\alpha

alpha

\alpha

$\alpha$

α

 

\Alpha

\Alpha

$\Alpha$

\beta

beta

\beta

$\beta$

β

 

\Beta

\Beta

$\Beta$

\gamma

gamma

\gamma

$\gamma$

γ

 

\Gamma

\Gamma

$\Gamma$

\delta

delta

\delta

$\delta$

Δ

 

\Delta

\Delta

$\Delta$

\infty

infinity (Chinese)

\infty

$\infty$

Infinity

 

infty (English)

$∞$

Geometri

Tag atau simbol

Fungsi

Contoh isi formula

Contoh input formula

Pengucapan

\pi

Dispatch

\pi=3.14159

$\pi =3.14159$

Pi equals 3.14159

\sin (sine

Trigonometric function

\sin (sine30^\circ=1\frac2

$\sin 30^\circ =\frac {1}{2}$

The sine of 30 degrees equals 1/2

\cos (cosine

$\cos 30^\circ =\frac {\sqrt {2}}{2}$

The cosine of 30 degrees equals the square root of two over two

\tan (tangent

$\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

\csc (cosecant

$\csc A$

cosecant A

\sec (secant

$\sec A$

secant A

\cot (cotangent

$\cot A$

cotangent A

\angle

Angle

\angle AB

$\angle AB$

Angle AB

∠AB

$∠AB$

^\circ

Degree

∠AB = 30^\circ

$∠AB = 30^\circ$

Angle AB equals 30 degrees

\odot

Circle

\odot

$\odot$

Circle

\overset\frown

Arc

\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}

\therefore AB \perp BC

$\therefore AB \perp BC$

Therefore, AB is perpendicular to BC

\triangle

Triangle

\triangleABC

$\triangle ABC$

Triangle ABC

△ABC

$△ABC$

\parallelogram

Parallelogram

\parallelogramABCD

$\parallelogram ABCD$

Parallelogram ABCD

\perp

Perpendicular

AB \perp BC

$AB \perp BC$

AB is perpendicular to BC

\bot

AB \bot BC

$AB \bot BC$

AB ⊥ BC

$AB ⊥ BC$

\parallel

Parallel

A\parallel B

$A\parallel B$

A is parallel to B

\equalparallel

Parallel and equal to

A\equalparallel B

$A\equalparallel B$

A is parallel and equal to B

\cong

Congruent

△ABC\cong△DEF

$△ABC\cong△DEF$

Triangle ABC is congruent to triangle DEF

Kondisi

Tag atau simbol

Fungsi

Contoh isi formula

Contoh input formula

Pengucapan

\implies

Launch

\implies 1+1=2

$\implies 1+1=2$

This implies that one plus one equals two

\iff

Equivalent to

p\iffq

$p\iffq$

p is equivalent to q

\because 

Because

\because a = b \therefore b=a

$\because a = b \therefore b=a$

Because a equals b, b equals a

\therefore 

Therefore

Unit

Unit harus dibungkus dalam tag \unit, \quantity, \mathit, \mathrm, atau \rm. Contohnya: \unit{cm}.

Tag atau simbol

Pengucapan

Contoh isi formula

Contoh input formula

Contoh pengucapan

mm

millimeter

5\quantity{mm}

$5\quantity{mm}$

5 millimeters

cm

centimeter

5\quantity{cm}

$5\quantity{cm}$

5 centimeters

dm

decimeter

5\quantity{dm}

$5\quantity{dm}$

5 decimeters

m

meter

5\quantity{m}

$5\quantity{m}$

5 meters

km

kilometer

5\quantity{km}

$5\quantity{km}$

5 kilometers

g

gram

5\quantity{g}

$5\quantity{g}$

5 grams

kg

kilogram

5\quantity{kg}

$5\quantity{kg}$

5 kilograms

t

ton

5\quantity{t}

$5\quantity{t}$

5 tons

mm^2

square millimeter

5\quantity{mm^2}

$5\quantity{mm^2}$

5 square millimeters

cm^2

square centimeter

5\quantity{cm^2}

$5\quantity{cm^2}$

5 square centimeters

dm^2

square decimeter

5\quantity{dm^2}

$5\quantity{dm^2}$

5 square decimeters

m^2

square meter

5\quantity{m^2}

$5\quantity{m^2}$

5 square meters

km^2

square kilometer

5\quantity{km^2}

$5\quantity{km^2}$

5 square kilometers

mm^3

cubic millimeter

5\quantity{mm^3}

$5\quantity{mm^3}$

5 cubic millimeters

cm^3

cubic centimeter

5\quantity{cm^3}

$5\quantity{cm^3}$

5 cubic centimeters

dm^3

cubic decimeter

5\quantity{dm^3}

$5\quantity{dm^3}$

5 cubic decimeters

m^3

cubic meter

5\quantity{m^3}

$5\quantity{m^3}$

5 cubic meters

km^3

cubic kilometer

5\quantity{km^3}

$5\quantity{km^3}$

5 cubic kilometers

ml

milliliter

5\quantity{ml}

$5\quantity{ml}$

5 milliliters

s

second

5\quantity{s}

$5\quantity{s}$

5 seconds

min

minute

5\quantity{min}

$5\quantity{min}$

5 minutes

h

hour

5\quantity{h}

$5\quantity{h}$

5 hours

km/h

kilometers per hour

5\quantity{km/h}

$5\quantity{km/h}$

5 kilometers per hour

g/l

grams per liter

5\quantity{g/l}

$5\quantity{g/l}$

5 grams per liter

Batasan

  • Batasan bahasa: Hanya bahasa Tiongkok yang didukung.

  • Batasan konten:

    • Formula hanya boleh menggunakan tag dan simbol yang tercantum dalam Tag dan simbol yang didukung.

    • Formula matematika dalam format Markdown, seperti ```math ... ```, tidak didukung.

    • Hanya sertakan formula di dalam pemisah. Konten lainnya dapat menyebabkan sintesis suara tidak akurat.

  • Ketersediaan model: cosyvoice-v2, cosyvoice-v3-flash, cosyvoice-v3-plus, cosyvoice-v3.5-flash, cosyvoice-v3.5-plus

FAQ

T: Mengapa formula yang saya masukkan tidak dibaca?

Periksa hal-hal berikut:

  1. Periksa pemisah: Pastikan formula telah dibungkus dengan benar menggunakan $...$, $$...$$, \(...\), atau \[...\].

  2. Periksa kompleksitas formula: Pastikan formula tidak mengandung tag atau simbol yang tidak didukung. Untuk informasi lebih lanjut, lihat Batasan dan Tag dan simbol yang didukung.

  3. Periksa karakter escape: Saat mengirim permintaan API, pastikan setiap backslash (\) dalam formula telah di-escape dengan benar menjadi \\.

T: Bagaimana cara menangani string yang berisi \ (backslash) dalam kode saya?

Dalam sebagian besar bahasa pemrograman, seperti Python, Java, dan JavaScript, backslash (\) merupakan karakter escape khusus dalam literal string dan data berformat JSON. Oleh karena itu, Anda harus melakukan escape terhadap backslash itu sendiri. Gunakan \\ untuk merepresentasikan satu \. Sebagai contoh, tulis \frac sebagai \\frac dalam kode Anda.