-
Notifications
You must be signed in to change notification settings - Fork 22
feat(model/cosyvoice): support hot_fix params and max_prompt_audio_length #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Alibaba, Inc. and its affiliates. | ||
|
|
||
| package com.alibaba.dashscope.audio.ttsv2; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
|
|
||
| /** Hot fix configuration for speech synthesis, including pronunciation and replace rules. */ | ||
| @Data | ||
| public class ParamHotFix { | ||
|
|
||
| /** Pronunciation rules to customize specific words. */ | ||
| private List<PronunciationItem> pronunciation; | ||
|
|
||
| /** Replace rules to replace specific words with others. */ | ||
| private List<ReplaceItem> replace; | ||
|
|
||
| public ArrayList<Object> getPronunciation() { | ||
| if (pronunciation == null || pronunciation.isEmpty()) { | ||
| return null; | ||
| } | ||
| ArrayList<Object> pronunciationList = new ArrayList<>(); | ||
| for (PronunciationItem item : pronunciation) { | ||
| HashMap<String, String> pronunciationItem = new HashMap<>(); | ||
| pronunciationItem.put(item.getText(), item.getPinyin()); | ||
| pronunciationList.add(pronunciationItem); | ||
| } | ||
|
|
||
| return pronunciationList; | ||
| } | ||
|
|
||
| public ArrayList<Object> getReplace() { | ||
| if (replace == null || replace.isEmpty()) { | ||
| return null; | ||
| } | ||
| ArrayList<Object> replaceList = new ArrayList<>(); | ||
| for (ReplaceItem item : replace) { | ||
| HashMap<String, String> replaceItem = new HashMap<>(); | ||
| replaceItem.put(item.getText(), item.getReplacement()); | ||
| replaceList.add(replaceItem); | ||
| } | ||
|
|
||
| return replaceList; | ||
| } | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| public static class PronunciationItem { | ||
| private String text; | ||
| private String pinyin; | ||
| } | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| public static class ReplaceItem { | ||
| private String text; | ||
| private String replacement; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -55,6 +55,9 @@ public class SpeechSynthesisParam extends FullDuplexServiceParam { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Builder.Default private List<String> languageHints = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** synthesis style */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Builder.Default private int style = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Hot fix configuration for pronunciation and replace rules. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Builder.Default private ParamHotFix hotFix = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public Map<String, Object> getParameters() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -83,6 +86,20 @@ public Map<String, Object> getParameters() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (getStyle() != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params.put(SpeechSynthesisApiKeywords.STYLE, getStyle()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add hot fix parameters if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (getHotFix() != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> hotFixParams = new HashMap<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (getHotFix().getPronunciation() != null && !getHotFix().getPronunciation().isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hotFixParams.put(SpeechSynthesisApiKeywords.PRONUNCIATION, getHotFix().getPronunciation()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (getHotFix().getReplace() != null && !getHotFix().getReplace().isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hotFixParams.put(SpeechSynthesisApiKeywords.REPLACE, getHotFix().getReplace()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!hotFixParams.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params.put(SpeechSynthesisApiKeywords.HOT_FIX, hotFixParams); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+90
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block has a performance issue: Additionally, the method names
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params.putAll(parameters); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic allows the
voiceparameter from the genericparametersmap to overwrite the value from the dedicatedvoicefield if both are present. This can lead to unexpected behavior. The dedicatedvoicefield should have precedence. To fix this, you can check if thevoiceproperty has already been set on thejsonObjectbefore adding it from theparametersmap.