|
16 | 16 | import io.reactivex.BackpressureStrategy; |
17 | 17 | import io.reactivex.Emitter; |
18 | 18 | import io.reactivex.Flowable; |
| 19 | +import lombok.Builder; |
| 20 | +import lombok.Getter; |
| 21 | +import lombok.NonNull; |
| 22 | +import lombok.experimental.SuperBuilder; |
| 23 | +import lombok.extern.slf4j.Slf4j; |
| 24 | + |
19 | 25 | import java.io.ByteArrayOutputStream; |
20 | 26 | import java.io.IOException; |
21 | 27 | import java.nio.ByteBuffer; |
|
29 | 35 | import java.util.concurrent.TimeUnit; |
30 | 36 | import java.util.concurrent.atomic.AtomicBoolean; |
31 | 37 | import java.util.concurrent.atomic.AtomicReference; |
32 | | -import lombok.Builder; |
33 | | -import lombok.Getter; |
34 | | -import lombok.NonNull; |
35 | | -import lombok.experimental.SuperBuilder; |
36 | | -import lombok.extern.slf4j.Slf4j; |
37 | 38 |
|
38 | 39 | /** @author lengjiayi */ |
39 | 40 | @Slf4j |
@@ -226,7 +227,7 @@ public Flowable<SpeechSynthesisResult> streamingCallAsFlowable(Flowable<String> |
226 | 227 | return duplexApi |
227 | 228 | .duplexCall( |
228 | 229 | StreamInputTtsParamWithStream.fromStreamInputTtsParam( |
229 | | - this.parameters, textStream, preRequestId)) |
| 230 | + this.parameters, textStream, preRequestId, false)) |
230 | 231 | .map(SpeechSynthesisResult::fromDashScopeResult) |
231 | 232 | .filter(item -> !canceled.get()) |
232 | 233 | .doOnNext( |
@@ -277,7 +278,8 @@ public Flowable<SpeechSynthesisResult> callAsFlowable(String text) |
277 | 278 | .start(); |
278 | 279 | }, |
279 | 280 | BackpressureStrategy.BUFFER), |
280 | | - preRequestId)) |
| 281 | + preRequestId, |
| 282 | + true)) |
281 | 283 | .map(SpeechSynthesisResult::fromDashScopeResult) |
282 | 284 | .doOnNext( |
283 | 285 | result -> { |
@@ -306,7 +308,7 @@ public Flowable<SpeechSynthesisResult> callAsFlowable(String text) |
306 | 308 | * Start voice transcription: Establish a connection with the server, send a voice transcription |
307 | 309 | * request, and synchronously receive confirmation from the server. |
308 | 310 | */ |
309 | | - private void startStream() { |
| 311 | + private void startStream(boolean enableSsml) { |
310 | 312 |
|
311 | 313 | startStreamTimeStamp = System.currentTimeMillis(); |
312 | 314 | recvAudioLength = 0; |
@@ -350,7 +352,7 @@ private void startStream() { |
350 | 352 | try { |
351 | 353 | duplexApi.duplexCall( |
352 | 354 | SpeechSynthesizer.StreamInputTtsParamWithStream.fromStreamInputTtsParam( |
353 | | - this.parameters, textFrames, preRequestId), |
| 355 | + this.parameters, textFrames, preRequestId, enableSsml), |
354 | 356 | new ResultCallback<DashScopeResult>() { |
355 | 357 | // private Sentence lastSentence = null; |
356 | 358 |
|
@@ -409,6 +411,9 @@ public void onEvent(DashScopeResult message) { |
409 | 411 | log.error("Failed to parse response: {}", message, e); |
410 | 412 | callback.onError(e); |
411 | 413 | } |
| 414 | + if (speechSynthesisResult.getRequestId() == null) { |
| 415 | + speechSynthesisResult.setRequestId(preRequestId); |
| 416 | + } |
412 | 417 | callback.onEvent(speechSynthesisResult); |
413 | 418 | } |
414 | 419 |
|
@@ -583,7 +588,7 @@ public void streamingCancel() { |
583 | 588 | public void streamingCall(String text) { |
584 | 589 | if (isFirst) { |
585 | 590 | isFirst = false; |
586 | | - this.startStream(); |
| 591 | + this.startStream(false); |
587 | 592 | } |
588 | 593 | this.submitText(text); |
589 | 594 | } |
@@ -614,7 +619,7 @@ public void onComplete() {} |
614 | 619 | public void onError(Exception e) {} |
615 | 620 | }; |
616 | 621 | } |
617 | | - this.startStream(); |
| 622 | + this.startStream(true); |
618 | 623 | this.submitText(text); |
619 | 624 | if (this.asyncCall) { |
620 | 625 | this.asyncStreamingComplete(); |
@@ -650,11 +655,12 @@ private static class StreamInputTtsParamWithStream extends SpeechSynthesisParam |
650 | 655 | @NonNull private Flowable<String> textStream; |
651 | 656 |
|
652 | 657 | public static StreamInputTtsParamWithStream fromStreamInputTtsParam( |
653 | | - SpeechSynthesisParam param, Flowable<String> textStream, String preRequestId) { |
| 658 | + SpeechSynthesisParam param, Flowable<String> textStream, String preRequestId, boolean enableSsml) { |
654 | 659 | return StreamInputTtsParamWithStream.builder() |
655 | 660 | .headers(param.getHeaders()) |
656 | 661 | .parameters(param.getParameters()) |
657 | 662 | .parameter("pre_task_id", preRequestId) |
| 663 | + .parameter("enable_ssml", enableSsml) |
658 | 664 | .format(param.getFormat()) |
659 | 665 | .textStream(textStream) |
660 | 666 | .model(param.getModel()) |
|
0 commit comments