GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dashcope-sdk-python/docs/guides/realtime-audio.md at main · agentscope-ai-java/dashcope-sdk-python

Expand file tree

/

realtime-audio.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
93 lines (72 loc) · 3.25 KB
/

realtime-audio.md

Copy path

File metadata and controls

93 lines (72 loc) · 3.25 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Advanced Audio: Voice Cloning, Pronunciation Fixes, Translation, and Hot Words

English | 中文 | 日本語 | Español | 한국어

This guide covers advanced audio capabilities beyond the basic TTS/ASR examples in the README. All of these are real, verified SDK features with no dedicated sample script, so examples here are built directly from the source signatures and their own docstrings.

Voice Cloning (Voice Enrollment)

VoiceEnrollmentService (CosyVoice v2) lets you register a custom voice from a short audio sample, then use it as a voice= value in SpeechSynthesizer calls:

from dashscope.audio.tts_v2 import VoiceEnrollmentService

service = VoiceEnrollmentService()
voice_id = service.create_voice(
    target_model="cosyvoice-v2",
    prefix="myvoice",  # digits/lowercase letters only, <10 chars
    url="https://example.com/voice-sample.wav",
)
print(voice_id)

# List, inspect, or remove enrolled voices
for voice in service.list_voices(prefix="myvoice"):
    print(voice)
service.delete_voice(voice_id)

Pronunciation and Text Fixes

HotFix corrects mispronounced words or replaces text before synthesis (CosyVoice v2):

from dashscope.audio.tts_v2 import SpeechSynthesizer, HotFix

hot_fix = HotFix(
    pronunciation=[{"草地": "cao3 di4"}],
    replace=[{"草地": "草弟"}],
)
synthesizer = SpeechSynthesizer(model="cosyvoice-v2", voice="longxiaochun_v2", hot_fix=hot_fix)

Real-time Speech Translation

TranslationRecognizerRealtime transcribes and translates streaming audio in one pass:

from dashscope.audio.asr import TranslationRecognizerCallback, TranslationRecognizerRealtime

class Callback(TranslationRecognizerCallback):
    def on_event(self, request_id, transcription_result, translation_result, usage) -> None:
        if transcription_result is not None and transcription_result.is_sentence_end:
            print("transcript:", transcription_result.text)
        if translation_result is not None:
            translation = translation_result.get_translation("en")
            if translation.is_sentence_end:
                print("translation:", translation.text)

translator = TranslationRecognizerRealtime(
    model="gummy-realtime-v1",
    format="pcm",
    sample_rate=16000,
    transcription_enabled=True,
    translation_enabled=True,
    translation_target_languages=["en"],
    callback=Callback(),
)
translator.start()
with open("audio.pcm", "rb") as f:
    while chunk := f.read(3200):
        translator.send_audio_frame(chunk)
translator.stop()

Custom Hot Words for Speech Recognition

AsrPhraseManager boosts recognition accuracy for specific words (e.g. song names, jargon), then applies them via phrase_id on Transcription.call:

from dashscope.audio.asr import AsrPhraseManager, Transcription

# Values are boost weights, not counts
job = AsrPhraseManager.create_phrases(
    model="paraformer-v1",
    phrases={"下一首": 90, "上一首": 90},
)
phrase_id = job.output.job_id

response = Transcription.call(
    model=Transcription.Models.paraformer_v1,
    file_urls=["https://example.com/audio.wav"],
    phrase_id=phrase_id,
)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.