Skip to content

Commit 9266ebc

Browse files
committed
docs: address Copilot feedback - safer Java examples and fernignore polish
All 5 Copilot threads: - .fernignore: add trailing slashes on .claude/ and .agents/ to match the file's dir/ convention. Add a comment explaining that CLAUDE.md is a defensive entry (file may not exist in every checkout). - deepgram-java-speech-to-text/SKILL.md: guard channels + alternatives against empty results before indexing, matching the pattern in examples/listen/TranscribeUrl.java. Prevents IndexOutOfBoundsException on empty/quiet audio. - deepgram-java-text-to-speech/SKILL.md: close the FileOutputStream in an onDisconnected handler (previously leaked the file handle); log IO errors in the audio callback rather than rethrowing RuntimeException from the WebSocket thread. Matches examples/speak/StreamingTts.java. - deepgram-java-management-api/SKILL.md: guard projects.isEmpty() before indexing projects.get(0) — new accounts may have zero projects.
1 parent 101c847 commit 9266ebc

4 files changed

Lines changed: 42 additions & 10 deletions

File tree

.agents/skills/deepgram-java-management-api/SKILL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ for (ListProjectsV1ResponseProjectsItem project : projects) {
4949

5050
## Quick start — project models / keys
5151

52+
Pick a project from the list above. New accounts may have zero projects — guard against that before indexing.
53+
5254
```java
55+
if (projects.isEmpty()) {
56+
throw new IllegalStateException("No Deepgram projects are visible to this API key.");
57+
}
5358
String projectId = projects.get(0).getProjectId().orElseThrow();
5459

5560
client.manage().v1().projects().models().list(projectId);

.agents/skills/deepgram-java-speech-to-text/SKILL.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,21 @@ MediaTranscribeResponse result = client.listen().v1().media().transcribeUrl(requ
6262
result.visit(new MediaTranscribeResponse.Visitor<Void>() {
6363
@Override
6464
public Void visit(ListenV1Response response) {
65-
String transcript = response.getResults()
66-
.getChannels().get(0)
67-
.getAlternatives().orElse(java.util.Collections.emptyList())
68-
.get(0)
69-
.getTranscript().orElse("");
65+
// Guard channels + alternatives against empty results (matches examples/listen/TranscribeUrl.java).
66+
String transcript = "";
67+
java.util.List<?> channels = response.getResults().getChannels();
68+
if (channels != null && !channels.isEmpty()) {
69+
java.util.List<?> alternatives = response.getResults()
70+
.getChannels().get(0)
71+
.getAlternatives().orElse(java.util.Collections.emptyList());
72+
if (!alternatives.isEmpty()) {
73+
transcript = response.getResults()
74+
.getChannels().get(0)
75+
.getAlternatives().orElse(java.util.Collections.emptyList())
76+
.get(0)
77+
.getTranscript().orElse("");
78+
}
79+
}
7080
System.out.println(transcript);
7181
return null;
7282
}

.agents/skills/deepgram-java-text-to-speech/SKILL.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,32 @@ import com.deepgram.resources.speak.v1.types.SpeakV1FlushType;
5757
import com.deepgram.resources.speak.v1.types.SpeakV1Text;
5858
import com.deepgram.resources.speak.v1.websocket.V1WebSocketClient;
5959
import java.io.FileOutputStream;
60+
import java.io.IOException;
6061
import java.io.OutputStream;
6162
import java.util.concurrent.TimeUnit;
63+
import java.util.logging.Level;
64+
import java.util.logging.Logger;
6265

66+
Logger logger = Logger.getLogger("StreamingTts");
6367
V1WebSocketClient wsClient = client.speak().v1().v1WebSocket();
6468
OutputStream audioOutput = new FileOutputStream("output_streaming.wav");
6569

70+
// Log write failures rather than throwing from the WebSocket callback thread
71+
// (matches examples/speak/StreamingTts.java).
6672
wsClient.onSpeakV1Audio(audioData -> {
6773
try {
6874
audioOutput.write(audioData.toByteArray());
69-
} catch (Exception e) {
70-
throw new RuntimeException(e);
75+
} catch (IOException e) {
76+
logger.log(Level.SEVERE, "Failed to write streaming audio to output file.", e);
77+
}
78+
});
79+
80+
// Close the output stream when the server disconnects so we don't leak the file handle.
81+
wsClient.onDisconnected(message -> {
82+
try {
83+
audioOutput.close();
84+
} catch (IOException e) {
85+
logger.log(Level.WARNING, "Failed to close streaming audio output file.", e);
7186
}
7287
});
7388

.fernignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ examples/
5050
target/
5151

5252
# Agent files (Claude Code, OpenCode, other agent tools)
53-
# .agents/skills/ holds agent-agnostic skills discoverable via `npx skills`
53+
# .agents/skills/ holds agent-agnostic skills discoverable via `npx skills`.
54+
# CLAUDE.md is kept here defensively alongside AGENTS.md — some agent tooling
55+
# expects one name, some the other, and layouts vary across checkouts.
5456
CLAUDE.md
5557
AGENTS.md
56-
.claude
57-
.agents
58+
.claude/
59+
.agents/

0 commit comments

Comments
 (0)