77
88import com .alibaba .dashscope .base .FullDuplexServiceParam ;
99import io .reactivex .Flowable ;
10- import lombok .Builder ;
11- import lombok .Data ;
12- import lombok .EqualsAndHashCode ;
10+ import lombok .*;
1311import lombok .experimental .SuperBuilder ;
14- import lombok . val ;
12+ import org . jetbrains . annotations . NotNull ;
1513
14+ import java .util .ArrayList ;
1615import java .util .HashMap ;
1716import java .util .List ;
1817import java .util .Map ;
@@ -58,9 +57,25 @@ public Map<String, Object> getInputs() {
5857 public static class UpStream {
5958 private String type = "AudioOnly" ;
6059 private String mode ;
61- // private int sampleRate;
60+ private AsrPostProcessing asrPostProcessing ;
61+ @ Builder .Default private Integer sampleRate = 16000 ;
62+ private String vocabularyId = null ;
6263 @ Builder .Default private String audioFormat = CONST_AUDIO_FORMAT_PCM ; //support pcm/opus
6364 private Map <String , Object > passThroughParams ;
65+
66+ @ Builder
67+ @ Setter
68+ public static class AsrPostProcessing {
69+ private List <ReplaceWord > replaceWords ;
70+
71+ @ Builder
72+ @ Setter
73+ public static class ReplaceWord {
74+ private String source ;
75+ private String target ;
76+ private String matchMode ;
77+ }
78+ }
6479 }
6580
6681 @ Builder
@@ -83,6 +98,7 @@ public static class DialogAttributes {
8398 }
8499
85100 @ Builder
101+ @ Setter
86102 public static class ClientInfo {
87103 private String userId ;
88104 private Device device ;
@@ -91,6 +107,7 @@ public static class ClientInfo {
91107 private Object status ;
92108 private String activeForegroundApp ;
93109 private Map <String , Object > passThroughParams ;
110+ private String sdk ;
94111
95112 @ Builder
96113 public static class Network {
@@ -133,6 +150,8 @@ public void clearParameters() {
133150
134151 @ Builder
135152 public static class UpdateParams {
153+ UpStream upStream ;
154+ DownStream downStream ;
136155 List <Object > images ;
137156 BizParams bizParams ;
138157 ClientInfo clientInfo ;
@@ -146,6 +165,16 @@ public Map<String, Object> getParameters() {
146165 upStreamParams .put (CONST_NAME_UP_STREAM_TYPE , upStream .type );
147166 upStreamParams .put (CONST_NAME_UP_STREAM_MODE , upStream .mode );
148167 upStreamParams .put (CONST_NAME_UP_STREAM_AUDIO_FORMAT , upStream .audioFormat );
168+ if (upStream .asrPostProcessing != null ){
169+ final var asrPostProcessingParams = getUpstreamAsrPostProcessing ();
170+ if (!asrPostProcessingParams .isEmpty ()) {
171+ upStreamParams .put (CONST_NAME_ASR_POST_PROCESSING , asrPostProcessingParams );
172+ }
173+ }
174+ upStreamParams .put (CONST_NAME_DOWN_STREAM_SAMPLE_RATE , upStream .sampleRate );
175+ if (upStream .vocabularyId != null ) {
176+ upStreamParams .put (CONST_NAME_VOCABULARY_ID , upStream .vocabularyId );
177+ }
149178 if (upStream .passThroughParams != null ) {
150179 upStreamParams .putAll (upStream .passThroughParams );
151180 }
@@ -199,17 +228,32 @@ public Map<String, Object> getParameters() {
199228 if (clientInfo .passThroughParams != null ) {
200229 clientInfoParams .putAll (clientInfo .passThroughParams );
201230 }
231+ if (clientInfo .sdk != null ){
232+ clientInfoParams .put (CONST_NAME_CLIENT_INFO_SDK , clientInfo .sdk );
233+ }
202234 params .put (CONST_NAME_CLIENT_INFO , clientInfoParams );
203235 }
204236
205237 if (bizParams != null ) {
206238 val bizParamsParams = new HashMap <String , Object >();
207- bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_DEFINED_PARAMS , bizParams .userDefinedParams );
208- bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_DEFINED_TOKENS , bizParams .userDefinedTokens );
209- bizParamsParams .put (CONST_NAME_BIZ_PARAMS_TOOL_PROMPTS , bizParams .toolPrompts );
210- bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_QUERY_PARAMS , bizParams .userQueryParams );
211- bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_PROMPT_PARAMS , bizParams .userPromptParams );
212- bizParamsParams .put (CONST_NAME_BIZ_PARAMS_VIDEOS , bizParams .videos );
239+ if (bizParams .userDefinedParams != null ) {
240+ bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_DEFINED_PARAMS , bizParams .userDefinedParams );
241+ }
242+ if (bizParams .userDefinedTokens != null ) {
243+ bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_DEFINED_TOKENS , bizParams .userDefinedTokens );
244+ }
245+ if (bizParams .toolPrompts != null ) {
246+ bizParamsParams .put (CONST_NAME_BIZ_PARAMS_TOOL_PROMPTS , bizParams .toolPrompts );
247+ }
248+ if (bizParams .userQueryParams != null ) {
249+ bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_QUERY_PARAMS , bizParams .userQueryParams );
250+ }
251+ if (bizParams .userPromptParams != null ) {
252+ bizParamsParams .put (CONST_NAME_BIZ_PARAMS_USER_PROMPT_PARAMS , bizParams .userPromptParams );
253+ }
254+ if (bizParams .videos != null ) {
255+ bizParamsParams .put (CONST_NAME_BIZ_PARAMS_VIDEOS , bizParams .videos );
256+ }
213257 if (bizParams .passThroughParams != null ) {
214258 bizParamsParams .putAll (bizParams .passThroughParams );
215259 }
@@ -222,6 +266,22 @@ public Map<String, Object> getParameters() {
222266 return params ;
223267 }
224268
269+ private @ NotNull HashMap <String , Object > getUpstreamAsrPostProcessing () {
270+ val asrPostProcessingParams = new HashMap <String , Object >();
271+ if (upStream .asrPostProcessing .replaceWords != null ) {
272+ val replaceWords = new ArrayList <Map <String , Object >>();
273+ for (val replaceWord : upStream .asrPostProcessing .replaceWords ) {
274+ val replaceWordObj = new HashMap <String , Object >();
275+ replaceWordObj .put (CONST_NAME_REPLACE_WORD_SOURCE , replaceWord .source );
276+ replaceWordObj .put (CONST_NAME_REPLACE_WORD_TARGET , replaceWord .target );
277+ replaceWordObj .put (CONST_NAME_REPLACE_WORD_MATCH_MODE , replaceWord .matchMode );
278+ replaceWords .add (replaceWordObj );
279+ }
280+ asrPostProcessingParams .put (CONST_NAME_REPLACE_WORDS , replaceWords );
281+ }
282+ return asrPostProcessingParams ;
283+ }
284+
225285 @ Override
226286 public Flowable <Object > getStreamingData () {
227287 return null ;
0 commit comments