Skip to content

Commit a6f5e44

Browse files
authored
Merge pull request #36 from lengjiayi/cosyvoice_opus
[Add] cosyvoice opus format
2 parents f6fd704 + 7390dd1 commit a6f5e44

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

dashscope/audio/tts_v2/speech_synthesizer.py

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,39 @@ def on_data(self, data: bytes) -> None:
4343

4444
@unique
4545
class AudioFormat(Enum):
46-
DEFAULT = ('Default', 0, '0', '0')
47-
WAV_8000HZ_MONO_16BIT = ('wav', 8000, 'mono', '16bit')
48-
WAV_16000HZ_MONO_16BIT = ('wav', 16000, 'mono', '16bit')
49-
WAV_22050HZ_MONO_16BIT = ('wav', 22050, 'mono', '16bit')
50-
WAV_24000HZ_MONO_16BIT = ('wav', 24000, 'mono', '16bit')
51-
WAV_44100HZ_MONO_16BIT = ('wav', 44100, 'mono', '16bit')
52-
WAV_48000HZ_MONO_16BIT = ('wav', 48000, 'mono', '16bit')
53-
54-
MP3_8000HZ_MONO_128KBPS = ('mp3', 8000, 'mono', '128kbps')
55-
MP3_16000HZ_MONO_128KBPS = ('mp3', 16000, 'mono', '128kbps')
56-
MP3_22050HZ_MONO_256KBPS = ('mp3', 22050, 'mono', '256kbps')
57-
MP3_24000HZ_MONO_256KBPS = ('mp3', 24000, 'mono', '256kbps')
58-
MP3_44100HZ_MONO_256KBPS = ('mp3', 44100, 'mono', '256kbps')
59-
MP3_48000HZ_MONO_256KBPS = ('mp3', 48000, 'mono', '256kbps')
60-
61-
PCM_8000HZ_MONO_16BIT = ('pcm', 8000, 'mono', '16bit')
62-
PCM_16000HZ_MONO_16BIT = ('pcm', 16000, 'mono', '16bit')
63-
PCM_22050HZ_MONO_16BIT = ('pcm', 22050, 'mono', '16bit')
64-
PCM_24000HZ_MONO_16BIT = ('pcm', 24000, 'mono', '16bit')
65-
PCM_44100HZ_MONO_16BIT = ('pcm', 44100, 'mono', '16bit')
66-
PCM_48000HZ_MONO_16BIT = ('pcm', 48000, 'mono', '16bit')
67-
46+
DEFAULT = ('Default', 0, '0', 0)
47+
WAV_8000HZ_MONO_16BIT = ('wav', 8000, 'mono', 0)
48+
WAV_16000HZ_MONO_16BIT = ('wav', 16000, 'mono', 16)
49+
WAV_22050HZ_MONO_16BIT = ('wav', 22050, 'mono', 16)
50+
WAV_24000HZ_MONO_16BIT = ('wav', 24000, 'mono', 16)
51+
WAV_44100HZ_MONO_16BIT = ('wav', 44100, 'mono', 16)
52+
WAV_48000HZ_MONO_16BIT = ('wav', 48000, 'mono', 16)
53+
54+
MP3_8000HZ_MONO_128KBPS = ('mp3', 8000, 'mono', 128)
55+
MP3_16000HZ_MONO_128KBPS = ('mp3', 16000, 'mono', 128)
56+
MP3_22050HZ_MONO_256KBPS = ('mp3', 22050, 'mono', 256)
57+
MP3_24000HZ_MONO_256KBPS = ('mp3', 24000, 'mono', 256)
58+
MP3_44100HZ_MONO_256KBPS = ('mp3', 44100, 'mono', 256)
59+
MP3_48000HZ_MONO_256KBPS = ('mp3', 48000, 'mono', 256)
60+
61+
PCM_8000HZ_MONO_16BIT = ('pcm', 8000, 'mono', 16)
62+
PCM_16000HZ_MONO_16BIT = ('pcm', 16000, 'mono', 16)
63+
PCM_22050HZ_MONO_16BIT = ('pcm', 22050, 'mono', 16)
64+
PCM_24000HZ_MONO_16BIT = ('pcm', 24000, 'mono', 16)
65+
PCM_44100HZ_MONO_16BIT = ('pcm', 44100, 'mono', 16)
66+
PCM_48000HZ_MONO_16BIT = ('pcm', 48000, 'mono', 16)
67+
68+
OGG_OPUS_8KHZ_MONO_32KBPS = ("opus", 8000, "mono", 32)
69+
OGG_OPUS_8KHZ_MONO_16KBPS = ("opus", 8000, "mono", 16)
70+
OGG_OPUS_16KHZ_MONO_16KBPS = ("opus", 16000, "mono", 16)
71+
OGG_OPUS_16KHZ_MONO_32KBPS = ("opus", 16000, "mono", 32)
72+
OGG_OPUS_16KHZ_MONO_64KBPS = ("opus", 16000, "mono", 64)
73+
OGG_OPUS_24KHZ_MONO_16KBPS = ("opus", 24000, "mono", 16)
74+
OGG_OPUS_24KHZ_MONO_32KBPS = ("opus", 24000, "mono", 32)
75+
OGG_OPUS_24KHZ_MONO_64KBPS = ("opus", 24000, "mono", 64)
76+
OGG_OPUS_48KHZ_MONO_16KBPS = ("opus", 48000, "mono", 16)
77+
OGG_OPUS_48KHZ_MONO_32KBPS = ("opus", 48000, "mono", 32)
78+
OGG_OPUS_48KHZ_MONO_64KBPS = ("opus", 48000, "mono", 64)
6879
def __init__(self, format, sample_rate, channels, bit_rate):
6980
self.format = format
7081
self.sample_rate = sample_rate
@@ -83,6 +94,7 @@ def __init__(
8394
voice,
8495
format='wav',
8596
sample_rate=16000,
97+
bit_rate=64000,
8698
volume=50,
8799
speech_rate=1.0,
88100
pitch_rate=1.0,
@@ -93,6 +105,7 @@ def __init__(
93105
self.model = model
94106
self.format = format
95107
self.sample_rate = sample_rate
108+
self.bit_rate = bit_rate
96109
self.volume = volume
97110
self.speech_rate = speech_rate
98111
self.pitch_rate = pitch_rate
@@ -146,6 +159,8 @@ def getStartRequest(self, additional_params=None):
146159
},
147160
},
148161
}
162+
if self.format == 'opus':
163+
cmd['payload']['parameters']['bit_rate'] = self.bit_rate
149164
if additional_params:
150165
cmd['payload']['parameters'].update(additional_params)
151166
return json.dumps(cmd)
@@ -252,6 +267,7 @@ def __init__(
252267
voice=voice,
253268
format=format.format,
254269
sample_rate=format.sample_rate,
270+
bit_rate = format.bit_rate,
255271
volume=volume,
256272
speech_rate=speech_rate,
257273
pitch_rate=pitch_rate,

0 commit comments

Comments
 (0)