-
Notifications
You must be signed in to change notification settings - Fork 6
refactor: update tts asr api and samples #73
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3401da2
test:ceshi
666ycy a19a765
Update README_CN.md
666ycy ce91ca9
Merge remote-tracking branch 'origin/test' into test
666ycy 25b9742
fix:Improve text-to-speech functionality
666ycy 4cbaed1
fix:Improve text-to-speech functionality
666ycy 2596c0c
fix:Improve text-to-speech and speech-to-text functionalities.
666ycy 45b40c8
fix: Add supplementary annotation information
666ycy 34e4284
Update README_CN.md
666ycy f017aa9
fix: Modify code
666ycy 9f261f2
fix: Modify code
666ycy 7ed0bd5
fix: Modify code
666ycy 5dbc718
fix: Modify code
666ycy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
samples/src/main/ai.z.openapi.samples/AudioSpeechStreamExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package ai.z.openapi.samples; | ||
|
|
||
| import ai.z.openapi.ZaiClient; | ||
| import ai.z.openapi.core.Constants; | ||
| import ai.z.openapi.service.audio.AudioSpeechRequest; | ||
| import ai.z.openapi.service.audio.AudioSpeechStreamingResponse; | ||
| import ai.z.openapi.service.model.Delta; | ||
| import ai.z.openapi.service.model.ModelData; | ||
|
|
||
| /** | ||
| * Streaming Audio Speech Example | ||
| * Demonstrates how to use ZaiClient for streaming text-to-speech conversion | ||
| */ | ||
| public class AudioSpeechStreamExample { | ||
|
|
||
| public static void main(String[] args) { | ||
| // Create client, recommended to set API Key via environment variable | ||
| // export ZAI_API_KEY=your.api_key | ||
| // for Z.ai use the `ZaiClient`, for Zhipu AI use the ZhipuAiClient.builder().ofZHIPU().build() | ||
| ZaiClient client = ZaiClient.builder().ofZAI().build(); | ||
|
|
||
| // Create speech request with streaming enabled | ||
| AudioSpeechRequest request = AudioSpeechRequest.builder() | ||
| .model(Constants.ModelTTS) | ||
| .input("Hello, how's the weather today") | ||
| .voice("tongtong") | ||
| .responseFormat("pcm") | ||
| .stream(true) // Enable streaming response | ||
| .build(); | ||
|
|
||
| try { | ||
| // Execute streaming request | ||
| AudioSpeechStreamingResponse response = client.audio().createStreamingSpeech(request); | ||
|
|
||
| if (response.isSuccess() && response.getFlowable() != null) { | ||
| System.out.println("Starting streaming TTS response..."); | ||
|
|
||
| response.getFlowable().subscribe( | ||
| data -> { | ||
| // Process each streaming response chunk | ||
| if (data.getChoices() != null && !data.getChoices().isEmpty()) { | ||
| // Get content of current chunk | ||
| Delta delta = data.getChoices().get(0).getDelta(); | ||
|
|
||
| // Print current audio content (base64 encoded) | ||
| if (delta != null && delta.getContent() != null) { | ||
| System.out.println("Received audio chunk: " + delta.getContent()); | ||
| } | ||
| } | ||
| }, | ||
| error -> System.err.println("\nStream error: " + error.getMessage()), | ||
| // Process streaming response completion event | ||
| () -> System.out.println("\nStreaming TTS completed") | ||
| ); | ||
|
|
||
| // Wait for streaming to complete | ||
| Thread.sleep(10000); | ||
| } else { | ||
| System.err.println("Error: " + response.getMsg()); | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println("Exception occurred: " + e.getMessage()); | ||
| e.printStackTrace(); | ||
| } finally { | ||
| client.close(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.