Skip to content

Commit e7d237c

Browse files
add response
1 parent 4db7356 commit e7d237c

File tree

5 files changed

+166
-17
lines changed

5 files changed

+166
-17
lines changed

sdk/cognitiveservices/azure-ai-speech-transcription/customization/src/main/java/SpeechTranscriptionCustomization.java

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private void customizeDiarizationOptionsToJson(PackageCustomization packageCusto
114114
/**
115115
* Customize TranscriptionOptions to:
116116
* 1. Add AudioFileDetails field (final)
117-
* 2. Add initialization to default constructor
117+
* 2. Remove default no-arg constructor
118118
* 3. Add constructor with String audioUrl parameter
119119
* 4. Add constructor with AudioFileDetails parameter
120120
* 5. Make setAudioUrl() private instead of public
@@ -129,15 +129,12 @@ private void customizeTranscriptionOptions(PackageCustomization packageCustomiza
129129
com.github.javaparser.ast.Modifier.Keyword.PRIVATE,
130130
com.github.javaparser.ast.Modifier.Keyword.FINAL);
131131

132-
// Update default constructor to initialize audioFileDetails
132+
// Remove default no-arg constructor
133133
clazz.getConstructors()
134134
.stream()
135135
.filter(c -> c.getParameters().isEmpty())
136136
.findFirst()
137-
.ifPresent(defaultConstructor -> {
138-
BlockStmt body = defaultConstructor.getBody();
139-
body.addStatement(0, parseStatement("this.audioFileDetails = null;"));
140-
});
137+
.ifPresent(com.github.javaparser.ast.Node::remove);
141138

142139
// Add constructor with String audioUrl parameter
143140
ConstructorDeclaration audioUrlConstructor = clazz.addConstructor(Modifier.Keyword.PUBLIC);
@@ -166,7 +163,7 @@ private void customizeTranscriptionOptions(PackageCustomization packageCustomiza
166163

167164
/**
168165
* Customize TranscriptionClient to add public transcribe(TranscriptionOptions) method
169-
* that hides TranscriptionContent construction.
166+
* that hides TranscriptionContent construction and add transcribeWithResponse method.
170167
*
171168
* @param packageCustomization the package customization
172169
*/
@@ -186,12 +183,48 @@ private void customizeTranscriptionClient(PackageCustomization packageCustomizat
186183
method.getAnnotationByName("Generated").ifPresent(com.github.javaparser.ast.Node::remove);
187184
}
188185
});
186+
187+
// Add public transcribeWithResponse method that returns Response<TranscriptionResult>
188+
com.github.javaparser.ast.body.MethodDeclaration transcribeWithResponseMethod = clazz.addMethod("transcribeWithResponse", Modifier.Keyword.PUBLIC)
189+
.addParameter("TranscriptionOptions", "options")
190+
.setType("Response<TranscriptionResult>");
191+
com.github.javaparser.ast.expr.NormalAnnotationExpr serviceMethodAnnotation = new com.github.javaparser.ast.expr.NormalAnnotationExpr();
192+
serviceMethodAnnotation.setName("ServiceMethod");
193+
serviceMethodAnnotation.addPair("returns", "ReturnType.SINGLE");
194+
transcribeWithResponseMethod.addAnnotation(serviceMethodAnnotation);
195+
transcribeWithResponseMethod.setBody(parseBlock(
196+
"{ TranscriptionContent requestContent = new TranscriptionContent(); "
197+
+ "requestContent.setOptions(options); "
198+
+ "RequestOptions requestOptions = new RequestOptions(); "
199+
+ "Response<BinaryData> response = transcribeWithResponse("
200+
+ "new MultipartFormDataHelper(requestOptions).serializeJsonField(\"definition\", requestContent.getOptions())"
201+
+ ".serializeFileField(\"audio\", requestContent.getAudio() == null ? null : requestContent.getAudio().getContent(), "
202+
+ "requestContent.getAudio() == null ? null : requestContent.getAudio().getContentType(), "
203+
+ "requestContent.getAudio() == null ? null : requestContent.getAudio().getFilename())"
204+
+ ".end().getRequestBody(), requestOptions); "
205+
+ "return new Response<TranscriptionResult>() { "
206+
+ "public int getStatusCode() { return response.getStatusCode(); } "
207+
+ "public com.azure.core.http.HttpHeaders getHeaders() { return response.getHeaders(); } "
208+
+ "public com.azure.core.http.HttpRequest getRequest() { return response.getRequest(); } "
209+
+ "public TranscriptionResult getValue() { return response.getValue().toObject(TranscriptionResult.class); } "
210+
+ "}; }"));
211+
transcribeWithResponseMethod.setJavadocComment(new Javadoc(parseText(
212+
"Transcribes the provided audio stream with the specified options."))
213+
.addBlockTag("param", "options the transcription options including audio file details or audio URL")
214+
.addBlockTag("throws", "IllegalArgumentException thrown if parameters fail the validation.")
215+
.addBlockTag("throws", "HttpResponseException thrown if the request is rejected by server.")
216+
.addBlockTag("throws", "ClientAuthenticationException thrown if the request is rejected by server on status code 401.")
217+
.addBlockTag("throws", "ResourceNotFoundException thrown if the request is rejected by server on status code 404.")
218+
.addBlockTag("throws", "ResourceModifiedException thrown if the request is rejected by server on status code 409.")
219+
.addBlockTag("throws", "RuntimeException all other wrapped checked exceptions if the request fails to be sent.")
220+
.addBlockTag("return", "the response containing the result of the transcribe operation."));
189221
});
190222
});
191223
}
192224

193225
/**
194-
* Customize TranscriptionAsyncClient to make transcribe(TranscriptionContent) package-private (internal).
226+
* Customize TranscriptionAsyncClient to make transcribe(TranscriptionContent) package-private (internal)
227+
* and add transcribeWithResponse method.
195228
*
196229
* @param packageCustomization the package customization
197230
*/
@@ -211,6 +244,41 @@ private void customizeTranscriptionAsyncClient(PackageCustomization packageCusto
211244
method.getAnnotationByName("Generated").ifPresent(com.github.javaparser.ast.Node::remove);
212245
}
213246
});
247+
248+
// Add public transcribeWithResponse method that returns Mono<Response<TranscriptionResult>>
249+
com.github.javaparser.ast.body.MethodDeclaration transcribeWithResponseMethod = clazz.addMethod("transcribeWithResponse", Modifier.Keyword.PUBLIC)
250+
.addParameter("TranscriptionOptions", "options")
251+
.setType("Mono<Response<TranscriptionResult>>");
252+
com.github.javaparser.ast.expr.NormalAnnotationExpr serviceMethodAnnotation = new com.github.javaparser.ast.expr.NormalAnnotationExpr();
253+
serviceMethodAnnotation.setName("ServiceMethod");
254+
serviceMethodAnnotation.addPair("returns", "ReturnType.SINGLE");
255+
transcribeWithResponseMethod.addAnnotation(serviceMethodAnnotation);
256+
transcribeWithResponseMethod.setBody(parseBlock(
257+
"{ TranscriptionContent requestContent = new TranscriptionContent(); "
258+
+ "requestContent.setOptions(options); "
259+
+ "RequestOptions requestOptions = new RequestOptions(); "
260+
+ "return transcribeWithResponse("
261+
+ "new MultipartFormDataHelper(requestOptions).serializeJsonField(\"definition\", requestContent.getOptions())"
262+
+ ".serializeFileField(\"audio\", requestContent.getAudio() == null ? null : requestContent.getAudio().getContent(), "
263+
+ "requestContent.getAudio() == null ? null : requestContent.getAudio().getContentType(), "
264+
+ "requestContent.getAudio() == null ? null : requestContent.getAudio().getFilename())"
265+
+ ".end().getRequestBody(), requestOptions)"
266+
+ ".map(response -> new Response<TranscriptionResult>() { "
267+
+ "public int getStatusCode() { return response.getStatusCode(); } "
268+
+ "public com.azure.core.http.HttpHeaders getHeaders() { return response.getHeaders(); } "
269+
+ "public com.azure.core.http.HttpRequest getRequest() { return response.getRequest(); } "
270+
+ "public TranscriptionResult getValue() { return response.getValue().toObject(TranscriptionResult.class); } "
271+
+ "}); }"));
272+
transcribeWithResponseMethod.setJavadocComment(new Javadoc(parseText(
273+
"Transcribes the provided audio stream with the specified options."))
274+
.addBlockTag("param", "options the transcription options including audio file details or audio URL")
275+
.addBlockTag("throws", "IllegalArgumentException thrown if parameters fail the validation.")
276+
.addBlockTag("throws", "HttpResponseException thrown if the request is rejected by server.")
277+
.addBlockTag("throws", "ClientAuthenticationException thrown if the request is rejected by server on status code 401.")
278+
.addBlockTag("throws", "ResourceNotFoundException thrown if the request is rejected by server on status code 404.")
279+
.addBlockTag("throws", "ResourceModifiedException thrown if the request is rejected by server on status code 409.")
280+
.addBlockTag("throws", "RuntimeException all other wrapped checked exceptions if the request fails to be sent.")
281+
.addBlockTag("return", "the response containing the result of the transcribe operation on successful completion of Mono."));
214282
});
215283
});
216284
}

sdk/cognitiveservices/azure-ai-speech-transcription/src/main/java/com/azure/ai/speech/transcription/TranscriptionAsyncClient.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,48 @@ public Mono<TranscriptionResult> transcribe(TranscriptionOptions options) {
142142
requestContent.setOptions(options);
143143
return transcribe(requestContent);
144144
}
145+
146+
/**
147+
* Transcribes the provided audio stream with the specified options.
148+
*
149+
* @param options the transcription options including audio file details or audio URL
150+
* @throws IllegalArgumentException thrown if parameters fail the validation.
151+
* @throws HttpResponseException thrown if the request is rejected by server.
152+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
153+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
154+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
155+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
156+
* @return the response containing the result of the transcribe operation on successful completion of Mono.
157+
*/
158+
public Mono<Response<TranscriptionResult>> transcribeWithResponse(TranscriptionOptions options) {
159+
TranscriptionContent requestContent = new TranscriptionContent();
160+
requestContent.setOptions(options);
161+
RequestOptions requestOptions = new RequestOptions();
162+
return transcribeWithResponse(
163+
new MultipartFormDataHelper(requestOptions).serializeJsonField("definition", requestContent.getOptions())
164+
.serializeFileField("audio",
165+
requestContent.getAudio() == null ? null : requestContent.getAudio().getContent(),
166+
requestContent.getAudio() == null ? null : requestContent.getAudio().getContentType(),
167+
requestContent.getAudio() == null ? null : requestContent.getAudio().getFilename())
168+
.end()
169+
.getRequestBody(),
170+
requestOptions).map(response -> new Response<TranscriptionResult>() {
171+
172+
public int getStatusCode() {
173+
return response.getStatusCode();
174+
}
175+
176+
public com.azure.core.http.HttpHeaders getHeaders() {
177+
return response.getHeaders();
178+
}
179+
180+
public com.azure.core.http.HttpRequest getRequest() {
181+
return response.getRequest();
182+
}
183+
184+
public TranscriptionResult getValue() {
185+
return response.getValue().toObject(TranscriptionResult.class);
186+
}
187+
});
188+
}
145189
}

sdk/cognitiveservices/azure-ai-speech-transcription/src/main/java/com/azure/ai/speech/transcription/TranscriptionClient.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,49 @@ public TranscriptionResult transcribe(TranscriptionOptions options) {
138138
requestContent.setOptions(options);
139139
return transcribe(requestContent);
140140
}
141+
142+
/**
143+
* Transcribes the provided audio stream with the specified options.
144+
*
145+
* @param options the transcription options including audio file details or audio URL
146+
* @throws IllegalArgumentException thrown if parameters fail the validation.
147+
* @throws HttpResponseException thrown if the request is rejected by server.
148+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
149+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
150+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
151+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
152+
* @return the response containing the result of the transcribe operation.
153+
*/
154+
public Response<TranscriptionResult> transcribeWithResponse(TranscriptionOptions options) {
155+
TranscriptionContent requestContent = new TranscriptionContent();
156+
requestContent.setOptions(options);
157+
RequestOptions requestOptions = new RequestOptions();
158+
Response<BinaryData> response = transcribeWithResponse(
159+
new MultipartFormDataHelper(requestOptions).serializeJsonField("definition", requestContent.getOptions())
160+
.serializeFileField("audio",
161+
requestContent.getAudio() == null ? null : requestContent.getAudio().getContent(),
162+
requestContent.getAudio() == null ? null : requestContent.getAudio().getContentType(),
163+
requestContent.getAudio() == null ? null : requestContent.getAudio().getFilename())
164+
.end()
165+
.getRequestBody(),
166+
requestOptions);
167+
return new Response<TranscriptionResult>() {
168+
169+
public int getStatusCode() {
170+
return response.getStatusCode();
171+
}
172+
173+
public com.azure.core.http.HttpHeaders getHeaders() {
174+
return response.getHeaders();
175+
}
176+
177+
public com.azure.core.http.HttpRequest getRequest() {
178+
return response.getRequest();
179+
}
180+
181+
public TranscriptionResult getValue() {
182+
return response.getValue().toObject(TranscriptionResult.class);
183+
}
184+
};
185+
}
141186
}

sdk/cognitiveservices/azure-ai-speech-transcription/src/main/java/com/azure/ai/speech/transcription/models/TranscriptionOptions.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ public final class TranscriptionOptions implements JsonSerializable<Transcriptio
7171
@Generated
7272
private PhraseListOptions phraseListOptions;
7373

74-
/**
75-
* Creates an instance of TranscriptionOptions class.
76-
*/
77-
@Generated
78-
public TranscriptionOptions() {
79-
this.audioFileDetails = null;
80-
}
81-
8274
/**
8375
* Get the audioUrl property: The URL of the audio to be transcribed. The audio must be shorter than 2 hours in
8476
* audio duration and smaller than 250 MB in size. If both Audio and AudioUrl are provided, Audio is used.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
directory: specification/cognitiveservices/Speech.Transcription
2-
commit: 3c52e9d0eadc790cef71559d1979694f1bb501be
2+
commit: c75a959c5b6b60b1e4f4ffde2e9f5516702b41c8
33
repo: Azure/azure-rest-api-specs
44
additionalDirectories:

0 commit comments

Comments
 (0)