diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/CHANGELOG.md b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/CHANGELOG.md new file mode 100644 index 000000000000..63b86ada8023 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release History + +## 0.1.0 (2025-05-08) +### Other Changes + +The package of `github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). + +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/LICENSE.txt b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/README.md b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/README.md new file mode 100644 index 000000000000..0eb3ddab333c --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/README.md @@ -0,0 +1,90 @@ +# Azure Azspeechbatchtranscription Module for Go + +The `azspeechbatchtranscription` module provides operations for working with Azure Azspeechbatchtranscription. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.18 or above (You could download and install the latest version of Go from [here](https://go.dev/doc/install). It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this [doc](https://go.dev/doc/manage-install).) + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Azspeechbatchtranscription module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Azspeechbatchtranscription. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Client Factory + +Azure Azspeechbatchtranscription module consists of one or more clients. We provide a client factory which could be used to create any client in this module. + +```go +clientFactory, err := azspeechbatchtranscription.NewClientFactory(, cred, nil) +``` + +You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +```go +options := arm.ClientOptions { + ClientOptions: azcore.ClientOptions { + Cloud: cloud.AzureChina, + }, +} +clientFactory, err := azspeechbatchtranscription.NewClientFactory(, cred, &options) +``` + +## Clients + +A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory. + +```go +client := clientFactory.() +``` + +## Fakes + +The fake package contains types used for constructing in-memory fake servers used in unit tests. +This allows writing tests to cover various success/error conditions without the need for connecting to a live service. + +Please see https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes for details and examples on how to use fakes. + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Azspeechbatchtranscription` label. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether +you need to provide a CLA and decorate the PR appropriately (e.g., label, +comment). Simply follow the instructions provided by the bot. You will only +need to do this once across all repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/batchtranscription_client.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/batchtranscription_client.go new file mode 100644 index 000000000000..9e6aadc7d868 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/batchtranscription_client.go @@ -0,0 +1,317 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechbatchtranscription + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strconv" + "strings" +) + +// BatchTranscriptionClient contains the methods for the BatchTranscription group. +// Don't use this type directly, use a constructor function instead. +type BatchTranscriptionClient struct { + internal *azcore.Client + endpoint string +} + +// DeleteTranscription - Deletes the specified transcription task. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-11-15 +// - id - The id of this entity. +// - options - BatchTranscriptionClientDeleteTranscriptionOptions contains the optional parameters for the BatchTranscriptionClient.DeleteTranscription +// method. +func (client *BatchTranscriptionClient) DeleteTranscription(ctx context.Context, id string, options *BatchTranscriptionClientDeleteTranscriptionOptions) (BatchTranscriptionClientDeleteTranscriptionResponse, error) { + var err error + const operationName = "BatchTranscriptionClient.DeleteTranscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.deleteTranscriptionCreateRequest(ctx, id, options) + if err != nil { + return BatchTranscriptionClientDeleteTranscriptionResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return BatchTranscriptionClientDeleteTranscriptionResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return BatchTranscriptionClientDeleteTranscriptionResponse{}, err + } + return BatchTranscriptionClientDeleteTranscriptionResponse{}, nil +} + +// deleteTranscriptionCreateRequest creates the DeleteTranscription request. +func (client *BatchTranscriptionClient) deleteTranscriptionCreateRequest(ctx context.Context, id string, _ *BatchTranscriptionClientDeleteTranscriptionOptions) (*policy.Request, error) { + host := "{endpoint}/speechtotext" + host = strings.ReplaceAll(host, "{endpoint}", client.endpoint) + urlPath := "/transcriptions/{id}" + if id == "" { + return nil, errors.New("parameter id cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{id}", url.PathEscape(id)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(host, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-11-15") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// GetTranscription - Gets the transcription identified by the given ID. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-11-15 +// - id - The id of this entity. +// - options - BatchTranscriptionClientGetTranscriptionOptions contains the optional parameters for the BatchTranscriptionClient.GetTranscription +// method. +func (client *BatchTranscriptionClient) GetTranscription(ctx context.Context, id string, options *BatchTranscriptionClientGetTranscriptionOptions) (BatchTranscriptionClientGetTranscriptionResponse, error) { + var err error + const operationName = "BatchTranscriptionClient.GetTranscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.getTranscriptionCreateRequest(ctx, id, options) + if err != nil { + return BatchTranscriptionClientGetTranscriptionResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return BatchTranscriptionClientGetTranscriptionResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return BatchTranscriptionClientGetTranscriptionResponse{}, err + } + resp, err := client.getTranscriptionHandleResponse(httpResp) + return resp, err +} + +// getTranscriptionCreateRequest creates the GetTranscription request. +func (client *BatchTranscriptionClient) getTranscriptionCreateRequest(ctx context.Context, id string, _ *BatchTranscriptionClientGetTranscriptionOptions) (*policy.Request, error) { + host := "{endpoint}/speechtotext" + host = strings.ReplaceAll(host, "{endpoint}", client.endpoint) + urlPath := "/transcriptions/{id}" + if id == "" { + return nil, errors.New("parameter id cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{id}", url.PathEscape(id)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(host, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-11-15") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getTranscriptionHandleResponse handles the GetTranscription response. +func (client *BatchTranscriptionClient) getTranscriptionHandleResponse(resp *http.Response) (BatchTranscriptionClientGetTranscriptionResponse, error) { + result := BatchTranscriptionClientGetTranscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.TranscriptionJob); err != nil { + return BatchTranscriptionClientGetTranscriptionResponse{}, err + } + return result, nil +} + +// NewListTranscriptionFilesPager - Gets the files of the transcription identified by the given ID +// +// Generated from API version 2024-11-15 +// - id - The id of this entity. +// - options - BatchTranscriptionClientListTranscriptionFilesOptions contains the optional parameters for the BatchTranscriptionClient.NewListTranscriptionFilesPager +// method. +func (client *BatchTranscriptionClient) NewListTranscriptionFilesPager(id string, options *BatchTranscriptionClientListTranscriptionFilesOptions) *runtime.Pager[BatchTranscriptionClientListTranscriptionFilesResponse] { + return runtime.NewPager(runtime.PagingHandler[BatchTranscriptionClientListTranscriptionFilesResponse]{ + More: func(page BatchTranscriptionClientListTranscriptionFilesResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *BatchTranscriptionClientListTranscriptionFilesResponse) (BatchTranscriptionClientListTranscriptionFilesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "BatchTranscriptionClient.NewListTranscriptionFilesPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listTranscriptionFilesCreateRequest(ctx, id, options) + }, nil) + if err != nil { + return BatchTranscriptionClientListTranscriptionFilesResponse{}, err + } + return client.listTranscriptionFilesHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listTranscriptionFilesCreateRequest creates the ListTranscriptionFiles request. +func (client *BatchTranscriptionClient) listTranscriptionFilesCreateRequest(ctx context.Context, id string, options *BatchTranscriptionClientListTranscriptionFilesOptions) (*policy.Request, error) { + host := "{endpoint}/speechtotext" + host = strings.ReplaceAll(host, "{endpoint}", client.endpoint) + urlPath := "/transcriptions/{id}/files" + if id == "" { + return nil, errors.New("parameter id cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{id}", url.PathEscape(id)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(host, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-11-15") + if options != nil && options.Filter != nil { + reqQP.Set("filter", *options.Filter) + } + if options != nil && options.Skip != nil { + reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) + } + if options != nil && options.Top != nil { + reqQP.Set("top", strconv.FormatInt(int64(*options.Top), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listTranscriptionFilesHandleResponse handles the ListTranscriptionFiles response. +func (client *BatchTranscriptionClient) listTranscriptionFilesHandleResponse(resp *http.Response) (BatchTranscriptionClientListTranscriptionFilesResponse, error) { + result := BatchTranscriptionClientListTranscriptionFilesResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SpeechToTextCustomPageTranscriptionFile); err != nil { + return BatchTranscriptionClientListTranscriptionFilesResponse{}, err + } + return result, nil +} + +// NewListTranscriptionsPager - Gets a list of transcriptions for the authenticated subscription. +// +// Generated from API version 2024-11-15 +// - options - BatchTranscriptionClientListTranscriptionsOptions contains the optional parameters for the BatchTranscriptionClient.NewListTranscriptionsPager +// method. +func (client *BatchTranscriptionClient) NewListTranscriptionsPager(options *BatchTranscriptionClientListTranscriptionsOptions) *runtime.Pager[BatchTranscriptionClientListTranscriptionsResponse] { + return runtime.NewPager(runtime.PagingHandler[BatchTranscriptionClientListTranscriptionsResponse]{ + More: func(page BatchTranscriptionClientListTranscriptionsResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *BatchTranscriptionClientListTranscriptionsResponse) (BatchTranscriptionClientListTranscriptionsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "BatchTranscriptionClient.NewListTranscriptionsPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listTranscriptionsCreateRequest(ctx, options) + }, nil) + if err != nil { + return BatchTranscriptionClientListTranscriptionsResponse{}, err + } + return client.listTranscriptionsHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listTranscriptionsCreateRequest creates the ListTranscriptions request. +func (client *BatchTranscriptionClient) listTranscriptionsCreateRequest(ctx context.Context, options *BatchTranscriptionClientListTranscriptionsOptions) (*policy.Request, error) { + host := "{endpoint}/speechtotext" + host = strings.ReplaceAll(host, "{endpoint}", client.endpoint) + urlPath := "/transcriptions" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(host, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-11-15") + if options != nil && options.Filter != nil { + reqQP.Set("filter", *options.Filter) + } + if options != nil && options.Skip != nil { + reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) + } + if options != nil && options.Top != nil { + reqQP.Set("top", strconv.FormatInt(int64(*options.Top), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listTranscriptionsHandleResponse handles the ListTranscriptions response. +func (client *BatchTranscriptionClient) listTranscriptionsHandleResponse(resp *http.Response) (BatchTranscriptionClientListTranscriptionsResponse, error) { + result := BatchTranscriptionClientListTranscriptionsResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SpeechToTextCustomPageTranscriptionJob); err != nil { + return BatchTranscriptionClientListTranscriptionsResponse{}, err + } + return result, nil +} + +// StartTranscription - Starts a new transcription job. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-11-15 +// - resource - The resource instance. +// - options - BatchTranscriptionClientStartTranscriptionOptions contains the optional parameters for the BatchTranscriptionClient.StartTranscription +// method. +func (client *BatchTranscriptionClient) StartTranscription(ctx context.Context, resource TranscriptionJob, options *BatchTranscriptionClientStartTranscriptionOptions) (BatchTranscriptionClientStartTranscriptionResponse, error) { + var err error + const operationName = "BatchTranscriptionClient.StartTranscription" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.startTranscriptionCreateRequest(ctx, resource, options) + if err != nil { + return BatchTranscriptionClientStartTranscriptionResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return BatchTranscriptionClientStartTranscriptionResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusCreated) { + err = runtime.NewResponseError(httpResp) + return BatchTranscriptionClientStartTranscriptionResponse{}, err + } + resp, err := client.startTranscriptionHandleResponse(httpResp) + return resp, err +} + +// startTranscriptionCreateRequest creates the StartTranscription request. +func (client *BatchTranscriptionClient) startTranscriptionCreateRequest(ctx context.Context, resource TranscriptionJob, _ *BatchTranscriptionClientStartTranscriptionOptions) (*policy.Request, error) { + host := "{endpoint}/speechtotext" + host = strings.ReplaceAll(host, "{endpoint}", client.endpoint) + urlPath := "/transcriptions:submit" + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(host, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-11-15") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + req.Raw().Header["Content-Type"] = []string{"application/json"} + if err := runtime.MarshalAsJSON(req, resource); err != nil { + return nil, err + } + return req, nil +} + +// startTranscriptionHandleResponse handles the StartTranscription response. +func (client *BatchTranscriptionClient) startTranscriptionHandleResponse(resp *http.Response) (BatchTranscriptionClientStartTranscriptionResponse, error) { + result := BatchTranscriptionClientStartTranscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.TranscriptionJob); err != nil { + return BatchTranscriptionClientStartTranscriptionResponse{}, err + } + return result, nil +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/ci.yml b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/ci.yml new file mode 100644 index 000000000000..44dcbf827121 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/ci.yml @@ -0,0 +1,27 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/ + +extends: + template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'ai/azspeechbatchtranscription/azspeechbatchtranscription' diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/constants.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/constants.go new file mode 100644 index 000000000000..6263fdb863ad --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/constants.go @@ -0,0 +1,142 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechbatchtranscription + +// FileKind - FileKind +type FileKind string + +const ( + // FileKindAcousticDataArchive - Type of data is acoustic data archive. + FileKindAcousticDataArchive FileKind = "AcousticDataArchive" + // FileKindAcousticDataTranscriptionV2 - Type of data is acoustic data transcription v2. + FileKindAcousticDataTranscriptionV2 FileKind = "AcousticDataTranscriptionV2" + // FileKindAudio - Type of data is audio. + FileKindAudio FileKind = "Audio" + // FileKindDatasetReport - Type of data is dataset report. + FileKindDatasetReport FileKind = "DatasetReport" + // FileKindEvaluationDetails - Type of data is evaluation details. + FileKindEvaluationDetails FileKind = "EvaluationDetails" + // FileKindLanguageData - Type of data is language data. + FileKindLanguageData FileKind = "LanguageData" + // FileKindModelReport - Type of data is model report. + FileKindModelReport FileKind = "ModelReport" + // FileKindOutputFormattingData - Type of data is output formatting input file. + FileKindOutputFormattingData FileKind = "OutputFormattingData" + // FileKindPronunciationData - Type of data is pronunciation data. + FileKindPronunciationData FileKind = "PronunciationData" + // FileKindTranscription - Type of data is transcription. + FileKindTranscription FileKind = "Transcription" + // FileKindTranscriptionReport - Type of data is transcription report. + FileKindTranscriptionReport FileKind = "TranscriptionReport" +) + +// PossibleFileKindValues returns the possible values for the FileKind const type. +func PossibleFileKindValues() []FileKind { + return []FileKind{ + FileKindAcousticDataArchive, + FileKindAcousticDataTranscriptionV2, + FileKindAudio, + FileKindDatasetReport, + FileKindEvaluationDetails, + FileKindLanguageData, + FileKindModelReport, + FileKindOutputFormattingData, + FileKindPronunciationData, + FileKindTranscription, + FileKindTranscriptionReport, + } +} + +// LanguageIdentificationMode - The mode used for language identification. +type LanguageIdentificationMode string + +const ( + // LanguageIdentificationModeContinuous - Continuous language identification (Default). + LanguageIdentificationModeContinuous LanguageIdentificationMode = "Continuous" + // LanguageIdentificationModeSingle - Single language identification. If no language can be identified, the error code NoLanguageIdentified + // is returned to the user. If there is ambiguity between multiple languages, the error code MultipleLanguagesIdentified is + // returned to the user. + LanguageIdentificationModeSingle LanguageIdentificationMode = "Single" +) + +// PossibleLanguageIdentificationModeValues returns the possible values for the LanguageIdentificationMode const type. +func PossibleLanguageIdentificationModeValues() []LanguageIdentificationMode { + return []LanguageIdentificationMode{ + LanguageIdentificationModeContinuous, + LanguageIdentificationModeSingle, + } +} + +// ProfanityFilterMode - Mode of profanity filtering. +type ProfanityFilterMode string + +const ( + // ProfanityFilterModeMasked - Mask the profanity with * except of the first letter, e.g., f*** + ProfanityFilterModeMasked ProfanityFilterMode = "Masked" + // ProfanityFilterModeNone - Disable profanity filtering. + ProfanityFilterModeNone ProfanityFilterMode = "None" + // ProfanityFilterModeRemoved - Remove profanity. + ProfanityFilterModeRemoved ProfanityFilterMode = "Removed" + // ProfanityFilterModeTags - Add "profanity" XML tags + ProfanityFilterModeTags ProfanityFilterMode = "Tags" +) + +// PossibleProfanityFilterModeValues returns the possible values for the ProfanityFilterMode const type. +func PossibleProfanityFilterModeValues() []ProfanityFilterMode { + return []ProfanityFilterMode{ + ProfanityFilterModeMasked, + ProfanityFilterModeNone, + ProfanityFilterModeRemoved, + ProfanityFilterModeTags, + } +} + +// PunctuationMode - The mode used for punctuation. +type PunctuationMode string + +const ( + // PunctuationModeAutomatic - Automatic punctuation. + PunctuationModeAutomatic PunctuationMode = "Automatic" + // PunctuationModeDictated - Dictated punctuation marks only, i.e., explicit punctuation. + PunctuationModeDictated PunctuationMode = "Dictated" + // PunctuationModeDictatedAndAutomatic - Dictated punctuation marks or automatic punctuation. + PunctuationModeDictatedAndAutomatic PunctuationMode = "DictatedAndAutomatic" + // PunctuationModeNone - No punctuation. + PunctuationModeNone PunctuationMode = "None" +) + +// PossiblePunctuationModeValues returns the possible values for the PunctuationMode const type. +func PossiblePunctuationModeValues() []PunctuationMode { + return []PunctuationMode{ + PunctuationModeAutomatic, + PunctuationModeDictated, + PunctuationModeDictatedAndAutomatic, + PunctuationModeNone, + } +} + +// TranscriptionStatus - Describe the current state of the API. +type TranscriptionStatus string + +const ( + // TranscriptionStatusFailed - The long running operation has failed. + TranscriptionStatusFailed TranscriptionStatus = "Failed" + // TranscriptionStatusNotStarted - The long running operation has not yet started. + TranscriptionStatusNotStarted TranscriptionStatus = "NotStarted" + // TranscriptionStatusRunning - The long running operation is currently processing. + TranscriptionStatusRunning TranscriptionStatus = "Running" + // TranscriptionStatusSucceeded - The long running operation has successfully completed. + TranscriptionStatusSucceeded TranscriptionStatus = "Succeeded" +) + +// PossibleTranscriptionStatusValues returns the possible values for the TranscriptionStatus const type. +func PossibleTranscriptionStatusValues() []TranscriptionStatus { + return []TranscriptionStatus{ + TranscriptionStatusFailed, + TranscriptionStatusNotStarted, + TranscriptionStatusRunning, + TranscriptionStatusSucceeded, + } +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/fake/batchtranscription_server.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/fake/batchtranscription_server.go new file mode 100644 index 000000000000..4ed4c00fe2fc --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/fake/batchtranscription_server.go @@ -0,0 +1,349 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "net/http" + "net/url" + "regexp" + "strconv" +) + +// BatchTranscriptionServer is a fake server for instances of the azspeechbatchtranscription.BatchTranscriptionClient type. +type BatchTranscriptionServer struct { + // DeleteTranscription is the fake for method BatchTranscriptionClient.DeleteTranscription + // HTTP status codes to indicate success: http.StatusNoContent + DeleteTranscription func(ctx context.Context, id string, options *azspeechbatchtranscription.BatchTranscriptionClientDeleteTranscriptionOptions) (resp azfake.Responder[azspeechbatchtranscription.BatchTranscriptionClientDeleteTranscriptionResponse], errResp azfake.ErrorResponder) + + // GetTranscription is the fake for method BatchTranscriptionClient.GetTranscription + // HTTP status codes to indicate success: http.StatusOK + GetTranscription func(ctx context.Context, id string, options *azspeechbatchtranscription.BatchTranscriptionClientGetTranscriptionOptions) (resp azfake.Responder[azspeechbatchtranscription.BatchTranscriptionClientGetTranscriptionResponse], errResp azfake.ErrorResponder) + + // NewListTranscriptionFilesPager is the fake for method BatchTranscriptionClient.NewListTranscriptionFilesPager + // HTTP status codes to indicate success: http.StatusOK + NewListTranscriptionFilesPager func(id string, options *azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionFilesOptions) (resp azfake.PagerResponder[azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionFilesResponse]) + + // NewListTranscriptionsPager is the fake for method BatchTranscriptionClient.NewListTranscriptionsPager + // HTTP status codes to indicate success: http.StatusOK + NewListTranscriptionsPager func(options *azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionsOptions) (resp azfake.PagerResponder[azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionsResponse]) + + // StartTranscription is the fake for method BatchTranscriptionClient.StartTranscription + // HTTP status codes to indicate success: http.StatusCreated + StartTranscription func(ctx context.Context, resource azspeechbatchtranscription.TranscriptionJob, options *azspeechbatchtranscription.BatchTranscriptionClientStartTranscriptionOptions) (resp azfake.Responder[azspeechbatchtranscription.BatchTranscriptionClientStartTranscriptionResponse], errResp azfake.ErrorResponder) +} + +// NewBatchTranscriptionServerTransport creates a new instance of BatchTranscriptionServerTransport with the provided implementation. +// The returned BatchTranscriptionServerTransport instance is connected to an instance of azspeechbatchtranscription.BatchTranscriptionClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewBatchTranscriptionServerTransport(srv *BatchTranscriptionServer) *BatchTranscriptionServerTransport { + return &BatchTranscriptionServerTransport{ + srv: srv, + newListTranscriptionFilesPager: newTracker[azfake.PagerResponder[azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionFilesResponse]](), + newListTranscriptionsPager: newTracker[azfake.PagerResponder[azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionsResponse]](), + } +} + +// BatchTranscriptionServerTransport connects instances of azspeechbatchtranscription.BatchTranscriptionClient to instances of BatchTranscriptionServer. +// Don't use this type directly, use NewBatchTranscriptionServerTransport instead. +type BatchTranscriptionServerTransport struct { + srv *BatchTranscriptionServer + newListTranscriptionFilesPager *tracker[azfake.PagerResponder[azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionFilesResponse]] + newListTranscriptionsPager *tracker[azfake.PagerResponder[azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionsResponse]] +} + +// Do implements the policy.Transporter interface for BatchTranscriptionServerTransport. +func (b *BatchTranscriptionServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return b.dispatchToMethodFake(req, method) +} + +func (b *BatchTranscriptionServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if batchTranscriptionServerTransportInterceptor != nil { + res.resp, res.err, intercepted = batchTranscriptionServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "BatchTranscriptionClient.DeleteTranscription": + res.resp, res.err = b.dispatchDeleteTranscription(req) + case "BatchTranscriptionClient.GetTranscription": + res.resp, res.err = b.dispatchGetTranscription(req) + case "BatchTranscriptionClient.NewListTranscriptionFilesPager": + res.resp, res.err = b.dispatchNewListTranscriptionFilesPager(req) + case "BatchTranscriptionClient.NewListTranscriptionsPager": + res.resp, res.err = b.dispatchNewListTranscriptionsPager(req) + case "BatchTranscriptionClient.StartTranscription": + res.resp, res.err = b.dispatchStartTranscription(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (b *BatchTranscriptionServerTransport) dispatchDeleteTranscription(req *http.Request) (*http.Response, error) { + if b.srv.DeleteTranscription == nil { + return nil, &nonRetriableError{errors.New("fake for method DeleteTranscription not implemented")} + } + const regexStr = `/transcriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + idParam, err := url.PathUnescape(matches[regex.SubexpIndex("id")]) + if err != nil { + return nil, err + } + respr, errRespr := b.srv.DeleteTranscription(req.Context(), idParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (b *BatchTranscriptionServerTransport) dispatchGetTranscription(req *http.Request) (*http.Response, error) { + if b.srv.GetTranscription == nil { + return nil, &nonRetriableError{errors.New("fake for method GetTranscription not implemented")} + } + const regexStr = `/transcriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + idParam, err := url.PathUnescape(matches[regex.SubexpIndex("id")]) + if err != nil { + return nil, err + } + respr, errRespr := b.srv.GetTranscription(req.Context(), idParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TranscriptionJob, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (b *BatchTranscriptionServerTransport) dispatchNewListTranscriptionFilesPager(req *http.Request) (*http.Response, error) { + if b.srv.NewListTranscriptionFilesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListTranscriptionFilesPager not implemented")} + } + newListTranscriptionFilesPager := b.newListTranscriptionFilesPager.get(req) + if newListTranscriptionFilesPager == nil { + const regexStr = `/transcriptions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/files` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + qp := req.URL.Query() + idParam, err := url.PathUnescape(matches[regex.SubexpIndex("id")]) + if err != nil { + return nil, err + } + topUnescaped, err := url.QueryUnescape(qp.Get("top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipUnescaped, err := url.QueryUnescape(qp.Get("skip")) + if err != nil { + return nil, err + } + skipParam, err := parseOptional(skipUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionFilesOptions + if topParam != nil || skipParam != nil || filterParam != nil { + options = &azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionFilesOptions{ + Top: topParam, + Skip: skipParam, + Filter: filterParam, + } + } + resp := b.srv.NewListTranscriptionFilesPager(idParam, options) + newListTranscriptionFilesPager = &resp + b.newListTranscriptionFilesPager.add(req, newListTranscriptionFilesPager) + server.PagerResponderInjectNextLinks(newListTranscriptionFilesPager, req, func(page *azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionFilesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListTranscriptionFilesPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + b.newListTranscriptionFilesPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListTranscriptionFilesPager) { + b.newListTranscriptionFilesPager.remove(req) + } + return resp, nil +} + +func (b *BatchTranscriptionServerTransport) dispatchNewListTranscriptionsPager(req *http.Request) (*http.Response, error) { + if b.srv.NewListTranscriptionsPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListTranscriptionsPager not implemented")} + } + newListTranscriptionsPager := b.newListTranscriptionsPager.get(req) + if newListTranscriptionsPager == nil { + qp := req.URL.Query() + topUnescaped, err := url.QueryUnescape(qp.Get("top")) + if err != nil { + return nil, err + } + topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + skipUnescaped, err := url.QueryUnescape(qp.Get("skip")) + if err != nil { + return nil, err + } + skipParam, err := parseOptional(skipUnescaped, func(v string) (int32, error) { + p, parseErr := strconv.ParseInt(v, 10, 32) + if parseErr != nil { + return 0, parseErr + } + return int32(p), nil + }) + if err != nil { + return nil, err + } + filterUnescaped, err := url.QueryUnescape(qp.Get("filter")) + if err != nil { + return nil, err + } + filterParam := getOptional(filterUnescaped) + var options *azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionsOptions + if topParam != nil || skipParam != nil || filterParam != nil { + options = &azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionsOptions{ + Top: topParam, + Skip: skipParam, + Filter: filterParam, + } + } + resp := b.srv.NewListTranscriptionsPager(options) + newListTranscriptionsPager = &resp + b.newListTranscriptionsPager.add(req, newListTranscriptionsPager) + server.PagerResponderInjectNextLinks(newListTranscriptionsPager, req, func(page *azspeechbatchtranscription.BatchTranscriptionClientListTranscriptionsResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListTranscriptionsPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + b.newListTranscriptionsPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListTranscriptionsPager) { + b.newListTranscriptionsPager.remove(req) + } + return resp, nil +} + +func (b *BatchTranscriptionServerTransport) dispatchStartTranscription(req *http.Request) (*http.Response, error) { + if b.srv.StartTranscription == nil { + return nil, &nonRetriableError{errors.New("fake for method StartTranscription not implemented")} + } + body, err := server.UnmarshalRequestAsJSON[azspeechbatchtranscription.TranscriptionJob](req) + if err != nil { + return nil, err + } + respr, errRespr := b.srv.StartTranscription(req.Context(), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TranscriptionJob, req) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to BatchTranscriptionServerTransport +var batchTranscriptionServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/fake/internal.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/fake/internal.go new file mode 100644 index 000000000000..41e62ec29233 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/fake/internal.go @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "reflect" + "sync" +) + +type result struct { + resp *http.Response + err error +} + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func getOptional[T any](v T) *T { + if reflect.ValueOf(v).IsZero() { + return nil + } + return &v +} + +func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) { + if v == "" { + return nil, nil + } + t, err := parse(v) + if err != nil { + return nil, err + } + return &t, err +} + +func newTracker[T any]() *tracker[T] { + return &tracker[T]{ + items: map[string]*T{}, + } +} + +type tracker[T any] struct { + items map[string]*T + mu sync.Mutex +} + +func (p *tracker[T]) get(req *http.Request) *T { + p.mu.Lock() + defer p.mu.Unlock() + if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok { + return item + } + return nil +} + +func (p *tracker[T]) add(req *http.Request, item *T) { + p.mu.Lock() + defer p.mu.Unlock() + p.items[server.SanitizePagerPollerPath(req.URL.Path)] = item +} + +func (p *tracker[T]) remove(req *http.Request) { + p.mu.Lock() + defer p.mu.Unlock() + delete(p.items, server.SanitizePagerPollerPath(req.URL.Path)) +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/go.mod b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/go.mod new file mode 100644 index 000000000000..8ac6fe68573b --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/go.mod @@ -0,0 +1,13 @@ +module github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription + +go 1.23.0 + +toolchain go1.23.8 + +require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect + golang.org/x/net v0.37.0 // indirect + golang.org/x/text v0.23.0 // indirect +) diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/go.sum b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/go.sum new file mode 100644 index 000000000000..cfff861c9769 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/go.sum @@ -0,0 +1,16 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 h1:DSDNVxqkoXJiko6x8a90zidoYqnYYa6c1MTzDKzKkTo= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1/go.mod h1:zGqV2R4Cr/k8Uye5w+dgQ06WJtEcbQG/8J7BB6hnCr4= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= +golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/models.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/models.go new file mode 100644 index 000000000000..e8b91b662fdd --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/models.go @@ -0,0 +1,222 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechbatchtranscription + +import "time" + +// DiarizationProperties - Speaker Identification Properties +type DiarizationProperties struct { + // REQUIRED; A value indicating whether speaker identification is enabled. + Enabled *bool + + // REQUIRED; A hint for the maximum number of speakers for diarization. Must be greater than 1 and less than 36. + MaxSpeakers *int32 +} + +// EntityError +type EntityError struct { + // READ-ONLY; The code of this error. + Code *string + + // READ-ONLY; The message for this error. + Message *string +} + +// EntityReference +type EntityReference struct { + // REQUIRED; The location of the referenced entity. + Self *string +} + +// FileLinks +type FileLinks struct { + // REQUIRED; The url to retrieve the content of this file. + ContentURL *string +} + +// FileProperties +type FileProperties struct { + // REQUIRED; The total duration in milliseconds of the file in case this file is an audio file. + DurationMilliseconds *int32 + + // REQUIRED; The size of the data in bytes. + Size *int32 +} + +// LanguageIdentificationProperties +type LanguageIdentificationProperties struct { + // REQUIRED; The candidate locales for language identification (example ["en-US", "de-DE", "es-ES"]). A minimum of 2 and a + // maximum of 10 candidate locales, including the main locale for the transcription, is supported for continuous mode. For + // single language identification, the maximum number of candidate locales is unbounded. + CandidateLocales []*string + + // The mode used for language identification. + Mode *LanguageIdentificationMode + + // An optional mapping of locales to speech model entities. If no model is given for a locale, the default base model is used. + // Keys must be locales contained in the candidate locales, values are entities for models of the respective locales. + SpeechModelMapping map[string]*EntityReference +} + +// SpeechToTextCustomPageTranscriptionFile - Page of entities. +type SpeechToTextCustomPageTranscriptionFile struct { + // READ-ONLY; A link to the next set of paginated results if there are more entities available; otherwise null. + NextLink *string + + // READ-ONLY; A list of entities limited by either the passed query parameters 'skip' and 'top' or their default values. + // + // When iterating through a list using pagination and deleting entities in parallel, some entities will be skipped in the + // results. + // It's recommended to build a list on the client and delete after the fetching of the complete list. + Values []*TranscriptionFile +} + +// SpeechToTextCustomPageTranscriptionJob - Page of entities. +type SpeechToTextCustomPageTranscriptionJob struct { + // READ-ONLY; A link to the next set of paginated results if there are more entities available; otherwise null. + NextLink *string + + // READ-ONLY; A list of entities limited by either the passed query parameters 'skip' and 'top' or their default values. + // + // When iterating through a list using pagination and deleting entities in parallel, some entities will be skipped in the + // results. + // It's recommended to build a list on the client and delete after the fetching of the complete list. + Values []*TranscriptionJob +} + +// TranscriptionFile +type TranscriptionFile struct { + // REQUIRED; The creation time of this file. The time stamp is encoded as ISO 8601 date and time format (see https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations). + Created *time.Time + + // REQUIRED; The name of this file. + DisplayName *string + + // REQUIRED; FileKind + Kind *FileKind + + // REQUIRED; FileLinks + Links *FileLinks + + // REQUIRED; FileProperties + Properties *FileProperties + + // READ-ONLY; The location of this entity. + Self *string +} + +// TranscriptionJob - Transcription +type TranscriptionJob struct { + // REQUIRED; The display name of the object. + DisplayName *string + + // REQUIRED; The locale of the contained data. If Language Identification is used, this locale is used to transcribe speech + // for which no language could be detected. + Locale *string + + // REQUIRED; TranscriptionProperties + Properties *TranscriptionProperties + + // READ-ONLY; The id of this entity. + ID *string + + // READ-ONLY; The location of this entity. + Self *string + + // READ-ONLY; The status of the object + Status *TranscriptionStatus + + // A URL for an Azure blob container that contains the audio files. A container is allowed to have a maximum size of 5GB and + // a maximum number of 10000 blobs. + // The maximum size for a blob is 2.5GB. + // Container SAS should contain 'r' (read) and 'l' (list) permissions. + // This property will not be returned in a response. + ContentContainerURL *string + + // A list of content urls to get audio files to transcribe. Up to 1000 urls are allowed. + // This property will not be returned in a response. + ContentUrls []*string + + // The custom properties of this entity. The maximum allowed key length is 64 characters, the maximum + // allowed value length is 256 characters and the count of allowed entries is 10. + CustomProperties map[string]*string + + // EntityReference + Dataset *EntityReference + + // The description of the object. + Description *string + + // TranscriptionLinks + Links *TranscriptionLinks + + // EntityReference + Model *EntityReference + + // READ-ONLY; The time-stamp when the object was created. + // The time stamp is encoded as ISO 8601 date and time format + // ("YYYY-MM-DDThh:mm:ssZ", see https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations). + Created *time.Time + + // READ-ONLY; The time-stamp when the current status was entered. + // The time stamp is encoded as ISO 8601 date and time format + // ("YYYY-MM-DDThh:mm:ssZ", see https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations). + LastActionDateTime *time.Time +} + +// TranscriptionLinks +type TranscriptionLinks struct { + // READ-ONLY; The location to get all files of this entity. See operation "Transcriptions_ListFiles" for more details. + Files *string +} + +// TranscriptionProperties +type TranscriptionProperties struct { + // REQUIRED; How long the transcription will be kept in the system after it has completed. Once the transcription reaches + // the time to live after completion(successful or failed) it will be automatically deleted. + // Note: When using BYOS (bring your own storage), the result files on the customer owned storage account will also be deleted.Use + // either destinationContainerUrl to specify a separate container for result files which will not be deleted when the timeToLive + // expires, or retrieve the result files through the API and store them as needed. + // The shortest supported duration is 6 hours, the longest supported duration is 31 days. 2 days (48 hours) is the recommended + // default value when data is consumed directly. + TimeToLiveHours *int32 + + // A collection of the requested channel numbers. In the default case, the channels 0 and 1 are considered. + Channels []*int32 + + // The requested destination container. + // Remarks + // When a destination container is used in combination with a timeToLive, the metadata of a transcription will be deleted + // normally, but the data stored in the destination container, including transcription results, will remain untouched, because + // no delete permissions are required for this container. + // To support automatic cleanup, either configure blob lifetimes on the container, or use "Bring your own Storage (BYOS)" + // instead of destinationContainerUrl, where blobs can be cleaned up. + DestinationContainerURL *string + + // Speaker Identification + Diarization *DiarizationProperties + + // A value indicating whether word level timestamps for the display form are requested. The default value is false. + DisplayFormWordLevelTimestampsEnabled *bool + + // EntityError + Error *EntityError + + // LanguageIdentificationProperties + LanguageIdentificationProperties *LanguageIdentificationProperties + + // Mode of profanity filtering. + ProfanityFilterMode *ProfanityFilterMode + + // The mode used for punctuation. + PunctuationMode *PunctuationMode + + // A value indicating whether word level timestamps are requested. The default value is false. + WordLevelTimestampsEnabled *bool + + // READ-ONLY; The duration in milliseconds of the transcription. + // Durations larger than 2^53-1 are not supported to ensure compatibility with JavaScript integers. + DurationMilliseconds *int32 +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/models_serde.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/models_serde.go new file mode 100644 index 000000000000..4607d8ce1a13 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/models_serde.go @@ -0,0 +1,500 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechbatchtranscription + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type DiarizationProperties. +func (d DiarizationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "enabled", d.Enabled) + populate(objectMap, "maxSpeakers", d.MaxSpeakers) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DiarizationProperties. +func (d *DiarizationProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "enabled": + err = unpopulate(val, "Enabled", &d.Enabled) + delete(rawMsg, key) + case "maxSpeakers": + err = unpopulate(val, "MaxSpeakers", &d.MaxSpeakers) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type EntityError. +func (e EntityError) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "code", e.Code) + populate(objectMap, "message", e.Message) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type EntityError. +func (e *EntityError) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "code": + err = unpopulate(val, "Code", &e.Code) + delete(rawMsg, key) + case "message": + err = unpopulate(val, "Message", &e.Message) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type EntityReference. +func (e EntityReference) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "self", e.Self) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type EntityReference. +func (e *EntityReference) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "self": + err = unpopulate(val, "Self", &e.Self) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FileLinks. +func (f FileLinks) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "contentUrl", f.ContentURL) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FileLinks. +func (f *FileLinks) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "contentUrl": + err = unpopulate(val, "ContentURL", &f.ContentURL) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FileProperties. +func (f FileProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "durationMilliseconds", f.DurationMilliseconds) + populate(objectMap, "size", f.Size) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FileProperties. +func (f *FileProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "durationMilliseconds": + err = unpopulate(val, "DurationMilliseconds", &f.DurationMilliseconds) + delete(rawMsg, key) + case "size": + err = unpopulate(val, "Size", &f.Size) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type LanguageIdentificationProperties. +func (l LanguageIdentificationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "candidateLocales", l.CandidateLocales) + populate(objectMap, "mode", l.Mode) + populate(objectMap, "speechModelMapping", l.SpeechModelMapping) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type LanguageIdentificationProperties. +func (l *LanguageIdentificationProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", l, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "candidateLocales": + err = unpopulate(val, "CandidateLocales", &l.CandidateLocales) + delete(rawMsg, key) + case "mode": + err = unpopulate(val, "Mode", &l.Mode) + delete(rawMsg, key) + case "speechModelMapping": + err = unpopulate(val, "SpeechModelMapping", &l.SpeechModelMapping) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", l, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SpeechToTextCustomPageTranscriptionFile. +func (s SpeechToTextCustomPageTranscriptionFile) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "@nextLink", s.NextLink) + populate(objectMap, "values", s.Values) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SpeechToTextCustomPageTranscriptionFile. +func (s *SpeechToTextCustomPageTranscriptionFile) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "@nextLink": + err = unpopulate(val, "NextLink", &s.NextLink) + delete(rawMsg, key) + case "values": + err = unpopulate(val, "Values", &s.Values) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SpeechToTextCustomPageTranscriptionJob. +func (s SpeechToTextCustomPageTranscriptionJob) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "@nextLink", s.NextLink) + populate(objectMap, "values", s.Values) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SpeechToTextCustomPageTranscriptionJob. +func (s *SpeechToTextCustomPageTranscriptionJob) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "@nextLink": + err = unpopulate(val, "NextLink", &s.NextLink) + delete(rawMsg, key) + case "values": + err = unpopulate(val, "Values", &s.Values) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscriptionFile. +func (t TranscriptionFile) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateDateTimeRFC3339(objectMap, "createdDateTime", t.Created) + populate(objectMap, "displayName", t.DisplayName) + populate(objectMap, "kind", t.Kind) + populate(objectMap, "links", t.Links) + populate(objectMap, "properties", t.Properties) + populate(objectMap, "self", t.Self) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscriptionFile. +func (t *TranscriptionFile) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "createdDateTime": + err = unpopulateDateTimeRFC3339(val, "Created", &t.Created) + delete(rawMsg, key) + case "displayName": + err = unpopulate(val, "DisplayName", &t.DisplayName) + delete(rawMsg, key) + case "kind": + err = unpopulate(val, "Kind", &t.Kind) + delete(rawMsg, key) + case "links": + err = unpopulate(val, "Links", &t.Links) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &t.Properties) + delete(rawMsg, key) + case "self": + err = unpopulate(val, "Self", &t.Self) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscriptionJob. +func (t TranscriptionJob) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "contentContainerUrl", t.ContentContainerURL) + populate(objectMap, "contentUrls", t.ContentUrls) + populateDateTimeRFC3339(objectMap, "createdDateTime", t.Created) + populate(objectMap, "customProperties", t.CustomProperties) + populate(objectMap, "dataset", t.Dataset) + populate(objectMap, "description", t.Description) + populate(objectMap, "displayName", t.DisplayName) + populate(objectMap, "id", t.ID) + populateDateTimeRFC3339(objectMap, "lastActionDateTime", t.LastActionDateTime) + populate(objectMap, "links", t.Links) + populate(objectMap, "locale", t.Locale) + populate(objectMap, "model", t.Model) + populate(objectMap, "properties", t.Properties) + populate(objectMap, "self", t.Self) + populate(objectMap, "status", t.Status) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscriptionJob. +func (t *TranscriptionJob) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "contentContainerUrl": + err = unpopulate(val, "ContentContainerURL", &t.ContentContainerURL) + delete(rawMsg, key) + case "contentUrls": + err = unpopulate(val, "ContentUrls", &t.ContentUrls) + delete(rawMsg, key) + case "createdDateTime": + err = unpopulateDateTimeRFC3339(val, "Created", &t.Created) + delete(rawMsg, key) + case "customProperties": + err = unpopulate(val, "CustomProperties", &t.CustomProperties) + delete(rawMsg, key) + case "dataset": + err = unpopulate(val, "Dataset", &t.Dataset) + delete(rawMsg, key) + case "description": + err = unpopulate(val, "Description", &t.Description) + delete(rawMsg, key) + case "displayName": + err = unpopulate(val, "DisplayName", &t.DisplayName) + delete(rawMsg, key) + case "id": + err = unpopulate(val, "ID", &t.ID) + delete(rawMsg, key) + case "lastActionDateTime": + err = unpopulateDateTimeRFC3339(val, "LastActionDateTime", &t.LastActionDateTime) + delete(rawMsg, key) + case "links": + err = unpopulate(val, "Links", &t.Links) + delete(rawMsg, key) + case "locale": + err = unpopulate(val, "Locale", &t.Locale) + delete(rawMsg, key) + case "model": + err = unpopulate(val, "Model", &t.Model) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &t.Properties) + delete(rawMsg, key) + case "self": + err = unpopulate(val, "Self", &t.Self) + delete(rawMsg, key) + case "status": + err = unpopulate(val, "Status", &t.Status) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscriptionLinks. +func (t TranscriptionLinks) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "files", t.Files) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscriptionLinks. +func (t *TranscriptionLinks) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "files": + err = unpopulate(val, "Files", &t.Files) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscriptionProperties. +func (t TranscriptionProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "channels", t.Channels) + populate(objectMap, "destinationContainerUrl", t.DestinationContainerURL) + populate(objectMap, "diarization", t.Diarization) + populate(objectMap, "displayFormWordLevelTimestampsEnabled", t.DisplayFormWordLevelTimestampsEnabled) + populate(objectMap, "durationMilliseconds", t.DurationMilliseconds) + populate(objectMap, "error", t.Error) + populate(objectMap, "languageIdentification", t.LanguageIdentificationProperties) + populate(objectMap, "profanityFilterMode", t.ProfanityFilterMode) + populate(objectMap, "punctuationMode", t.PunctuationMode) + populate(objectMap, "timeToLiveHours", t.TimeToLiveHours) + populate(objectMap, "wordLevelTimestampsEnabled", t.WordLevelTimestampsEnabled) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscriptionProperties. +func (t *TranscriptionProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "channels": + err = unpopulate(val, "Channels", &t.Channels) + delete(rawMsg, key) + case "destinationContainerUrl": + err = unpopulate(val, "DestinationContainerURL", &t.DestinationContainerURL) + delete(rawMsg, key) + case "diarization": + err = unpopulate(val, "Diarization", &t.Diarization) + delete(rawMsg, key) + case "displayFormWordLevelTimestampsEnabled": + err = unpopulate(val, "DisplayFormWordLevelTimestampsEnabled", &t.DisplayFormWordLevelTimestampsEnabled) + delete(rawMsg, key) + case "durationMilliseconds": + err = unpopulate(val, "DurationMilliseconds", &t.DurationMilliseconds) + delete(rawMsg, key) + case "error": + err = unpopulate(val, "Error", &t.Error) + delete(rawMsg, key) + case "languageIdentification": + err = unpopulate(val, "LanguageIdentificationProperties", &t.LanguageIdentificationProperties) + delete(rawMsg, key) + case "profanityFilterMode": + err = unpopulate(val, "ProfanityFilterMode", &t.ProfanityFilterMode) + delete(rawMsg, key) + case "punctuationMode": + err = unpopulate(val, "PunctuationMode", &t.PunctuationMode) + delete(rawMsg, key) + case "timeToLiveHours": + err = unpopulate(val, "TimeToLiveHours", &t.TimeToLiveHours) + delete(rawMsg, key) + case "wordLevelTimestampsEnabled": + err = unpopulate(val, "WordLevelTimestampsEnabled", &t.WordLevelTimestampsEnabled) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil || string(data) == "null" { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/options.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/options.go new file mode 100644 index 000000000000..e222f03b6beb --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/options.go @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechbatchtranscription + +// BatchTranscriptionClientDeleteTranscriptionOptions contains the optional parameters for the BatchTranscriptionClient.DeleteTranscription +// method. +type BatchTranscriptionClientDeleteTranscriptionOptions struct { + // placeholder for future optional parameters +} + +// BatchTranscriptionClientGetTranscriptionOptions contains the optional parameters for the BatchTranscriptionClient.GetTranscription +// method. +type BatchTranscriptionClientGetTranscriptionOptions struct { + // placeholder for future optional parameters +} + +// BatchTranscriptionClientListTranscriptionFilesOptions contains the optional parameters for the BatchTranscriptionClient.NewListTranscriptionFilesPager +// method. +type BatchTranscriptionClientListTranscriptionFilesOptions struct { + // Filter the result list using the given expression. + Filter *string + + // The number of result items to skip. + Skip *int32 + + // The number of result items to return. + Top *int32 +} + +// BatchTranscriptionClientListTranscriptionsOptions contains the optional parameters for the BatchTranscriptionClient.NewListTranscriptionsPager +// method. +type BatchTranscriptionClientListTranscriptionsOptions struct { + // Filter the result list using the given expression. + Filter *string + + // The number of result items to skip. + Skip *int32 + + // The number of result items to return. + Top *int32 +} + +// BatchTranscriptionClientStartTranscriptionOptions contains the optional parameters for the BatchTranscriptionClient.StartTranscription +// method. +type BatchTranscriptionClientStartTranscriptionOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/responses.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/responses.go new file mode 100644 index 000000000000..8c54a3ec5b5d --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/responses.go @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechbatchtranscription + +// BatchTranscriptionClientDeleteTranscriptionResponse contains the response from method BatchTranscriptionClient.DeleteTranscription. +type BatchTranscriptionClientDeleteTranscriptionResponse struct { + // placeholder for future response values +} + +// BatchTranscriptionClientGetTranscriptionResponse contains the response from method BatchTranscriptionClient.GetTranscription. +type BatchTranscriptionClientGetTranscriptionResponse struct { + // Transcription + TranscriptionJob +} + +// BatchTranscriptionClientListTranscriptionFilesResponse contains the response from method BatchTranscriptionClient.NewListTranscriptionFilesPager. +type BatchTranscriptionClientListTranscriptionFilesResponse struct { + // Page of entities. + SpeechToTextCustomPageTranscriptionFile +} + +// BatchTranscriptionClientListTranscriptionsResponse contains the response from method BatchTranscriptionClient.NewListTranscriptionsPager. +type BatchTranscriptionClientListTranscriptionsResponse struct { + // Page of entities. + SpeechToTextCustomPageTranscriptionJob +} + +// BatchTranscriptionClientStartTranscriptionResponse contains the response from method BatchTranscriptionClient.StartTranscription. +type BatchTranscriptionClientStartTranscriptionResponse struct { + // Transcription + TranscriptionJob +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/time_rfc3339.go b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/time_rfc3339.go new file mode 100644 index 000000000000..533755c6db30 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/time_rfc3339.go @@ -0,0 +1,109 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechbatchtranscription + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(?:Z|z|\+|-)(?:\d+:\d+)*"*$`) + +const ( + utcDateTime = "2006-01-02T15:04:05.999999999" + utcDateTimeJSON = `"` + utcDateTime + `"` + utcDateTimeNoT = "2006-01-02 15:04:05.999999999" + utcDateTimeJSONNoT = `"` + utcDateTimeNoT + `"` + dateTimeNoT = `2006-01-02 15:04:05.999999999Z07:00` + dateTimeJSON = `"` + time.RFC3339Nano + `"` + dateTimeJSONNoT = `"` + dateTimeNoT + `"` +) + +type dateTimeRFC3339 time.Time + +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = dateTimeJSON + } else if tzOffset { + layout = dateTimeJSONNoT + } else if hasT { + layout = utcDateTimeJSON + } else { + layout = utcDateTimeJSONNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + if len(data) == 0 { + return nil + } + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = time.RFC3339Nano + } else if tzOffset { + layout = dateTimeNoT + } else if hasT { + layout = utcDateTime + } else { + layout = utcDateTimeNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = dateTimeRFC3339(p) + return err +} + +func (t dateTimeRFC3339) String() string { + return time.Time(t).Format(time.RFC3339Nano) +} + +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*dateTimeRFC3339)(t) +} + +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || string(data) == "null" { + return nil + } + var aux dateTimeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +} diff --git a/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/tsp-location.yaml b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/tsp-location.yaml new file mode 100644 index 000000000000..3736afd9d514 --- /dev/null +++ b/sdk/ai/azspeechbatchtranscription/azspeechbatchtranscription/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/cognitiveservices/Speech.BatchTranscription +commit: 42d832f4bd16b04dd3cb124ca3e8dfaef1211bc2 +repo: Azure/azure-rest-api-specs +additionalDirectories: diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/CHANGELOG.md b/sdk/ai/azspeechtranscription/azspeechtranscription/CHANGELOG.md new file mode 100644 index 000000000000..8c84cb724872 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release History + +## 0.1.0 (2025-05-08) +### Other Changes + +The package of `github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechtranscription/azspeechtranscription` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). + +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/LICENSE.txt b/sdk/ai/azspeechtranscription/azspeechtranscription/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/README.md b/sdk/ai/azspeechtranscription/azspeechtranscription/README.md new file mode 100644 index 000000000000..6b1a80cf50b5 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/README.md @@ -0,0 +1,90 @@ +# Azure Azspeechtranscription Module for Go + +The `azspeechtranscription` module provides operations for working with Azure Azspeechtranscription. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/ai/azspeechtranscription/azspeechtranscription) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.18 or above (You could download and install the latest version of Go from [here](https://go.dev/doc/install). It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this [doc](https://go.dev/doc/manage-install).) + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Azspeechtranscription module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechtranscription/azspeechtranscription +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Azspeechtranscription. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Client Factory + +Azure Azspeechtranscription module consists of one or more clients. We provide a client factory which could be used to create any client in this module. + +```go +clientFactory, err := azspeechtranscription.NewClientFactory(, cred, nil) +``` + +You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +```go +options := arm.ClientOptions { + ClientOptions: azcore.ClientOptions { + Cloud: cloud.AzureChina, + }, +} +clientFactory, err := azspeechtranscription.NewClientFactory(, cred, &options) +``` + +## Clients + +A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory. + +```go +client := clientFactory.() +``` + +## Fakes + +The fake package contains types used for constructing in-memory fake servers used in unit tests. +This allows writing tests to cover various success/error conditions without the need for connecting to a live service. + +Please see https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes for details and examples on how to use fakes. + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Azspeechtranscription` label. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether +you need to provide a CLA and decorate the PR appropriately (e.g., label, +comment). Simply follow the instructions provided by the bot. You will only +need to do this once across all repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/ci.yml b/sdk/ai/azspeechtranscription/azspeechtranscription/ci.yml new file mode 100644 index 000000000000..e5bdd25326f5 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/ci.yml @@ -0,0 +1,27 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/ai/azspeechtranscription/azspeechtranscription/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/ai/azspeechtranscription/azspeechtranscription/ + +extends: + template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'ai/azspeechtranscription/azspeechtranscription' diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/constants.go b/sdk/ai/azspeechtranscription/azspeechtranscription/constants.go new file mode 100644 index 000000000000..5d7a85c96d46 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/constants.go @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechtranscription + +// ProfanityFilterMode - Mode of profanity filtering. +type ProfanityFilterMode string + +const ( + // ProfanityFilterModeMasked - Mask the profanity with * except of the first letter, e.g., f*** + ProfanityFilterModeMasked ProfanityFilterMode = "Masked" + // ProfanityFilterModeNone - Disable profanity filtering. + ProfanityFilterModeNone ProfanityFilterMode = "None" + // ProfanityFilterModeRemoved - Remove profanity. + ProfanityFilterModeRemoved ProfanityFilterMode = "Removed" + // ProfanityFilterModeTags - Add "profanity" XML tags + ProfanityFilterModeTags ProfanityFilterMode = "Tags" +) + +// PossibleProfanityFilterModeValues returns the possible values for the ProfanityFilterMode const type. +func PossibleProfanityFilterModeValues() []ProfanityFilterMode { + return []ProfanityFilterMode{ + ProfanityFilterModeMasked, + ProfanityFilterModeNone, + ProfanityFilterModeRemoved, + ProfanityFilterModeTags, + } +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/fake/internal.go b/sdk/ai/azspeechtranscription/azspeechtranscription/fake/internal.go new file mode 100644 index 000000000000..4123cf158a29 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/fake/internal.go @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import "net/http" + +type result struct { + resp *http.Response + err error +} + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/fake/transcription_server.go b/sdk/ai/azspeechtranscription/azspeechtranscription/fake/transcription_server.go new file mode 100644 index 000000000000..164ed0898643 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/fake/transcription_server.go @@ -0,0 +1,147 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package fake + +import ( + "bytes" + "context" + "encoding/json" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechtranscription/azspeechtranscription" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" + "io" + "mime" + "mime/multipart" + "net/http" +) + +// TranscriptionServer is a fake server for instances of the azspeechtranscription.TranscriptionClient type. +type TranscriptionServer struct { + // Transcribe is the fake for method TranscriptionClient.Transcribe + // HTTP status codes to indicate success: http.StatusOK + Transcribe func(ctx context.Context, body azspeechtranscription.TranscribeRequest, options *azspeechtranscription.TranscriptionClientTranscribeOptions) (resp azfake.Responder[azspeechtranscription.TranscriptionClientTranscribeResponse], errResp azfake.ErrorResponder) +} + +// NewTranscriptionServerTransport creates a new instance of TranscriptionServerTransport with the provided implementation. +// The returned TranscriptionServerTransport instance is connected to an instance of azspeechtranscription.TranscriptionClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewTranscriptionServerTransport(srv *TranscriptionServer) *TranscriptionServerTransport { + return &TranscriptionServerTransport{srv: srv} +} + +// TranscriptionServerTransport connects instances of azspeechtranscription.TranscriptionClient to instances of TranscriptionServer. +// Don't use this type directly, use NewTranscriptionServerTransport instead. +type TranscriptionServerTransport struct { + srv *TranscriptionServer +} + +// Do implements the policy.Transporter interface for TranscriptionServerTransport. +func (t *TranscriptionServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return t.dispatchToMethodFake(req, method) +} + +func (t *TranscriptionServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if transcriptionServerTransportInterceptor != nil { + res.resp, res.err, intercepted = transcriptionServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "TranscriptionClient.Transcribe": + res.resp, res.err = t.dispatchTranscribe(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (t *TranscriptionServerTransport) dispatchTranscribe(req *http.Request) (*http.Response, error) { + if t.srv.Transcribe == nil { + return nil, &nonRetriableError{errors.New("fake for method Transcribe not implemented")} + } + _, params, err := mime.ParseMediaType(req.Header.Get("Content-Type")) + if err != nil { + return nil, err + } + reader := multipart.NewReader(req.Body, params["boundary"]) + var body azspeechtranscription.TranscribeRequest + for { + var part *multipart.Part + part, err = reader.NextPart() + if errors.Is(err, io.EOF) { + break + } else if err != nil { + return nil, err + } + var content []byte + switch fn := part.FormName(); fn { + case "audio": + content, err = io.ReadAll(part) + if err != nil { + return nil, err + } + body.Audio.Body = streaming.NopCloser(bytes.NewReader(content)) + body.Audio.ContentType = part.Header.Get("Content-Type") + body.Audio.Filename = part.FileName() + case "definition": + content, err = io.ReadAll(part) + if err != nil { + return nil, err + } + if err = json.Unmarshal(content, &body.Options); err != nil { + return nil, err + } + default: + return nil, fmt.Errorf("unexpected part %s", fn) + } + } + respr, errRespr := t.srv.Transcribe(req.Context(), body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).TranscriptionResult, req) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to TranscriptionServerTransport +var transcriptionServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/go.mod b/sdk/ai/azspeechtranscription/azspeechtranscription/go.mod new file mode 100644 index 000000000000..98600f404335 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/go.mod @@ -0,0 +1,13 @@ +module github.com/Azure/azure-sdk-for-go/sdk/ai/azspeechtranscription/azspeechtranscription + +go 1.23.0 + +toolchain go1.23.8 + +require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect + golang.org/x/net v0.37.0 // indirect + golang.org/x/text v0.23.0 // indirect +) diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/go.sum b/sdk/ai/azspeechtranscription/azspeechtranscription/go.sum new file mode 100644 index 000000000000..cfff861c9769 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/go.sum @@ -0,0 +1,16 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 h1:DSDNVxqkoXJiko6x8a90zidoYqnYYa6c1MTzDKzKkTo= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1/go.mod h1:zGqV2R4Cr/k8Uye5w+dgQ06WJtEcbQG/8J7BB6hnCr4= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= +golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/models.go b/sdk/ai/azspeechtranscription/azspeechtranscription/models.go new file mode 100644 index 000000000000..96f6ca3af768 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/models.go @@ -0,0 +1,108 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechtranscription + +import "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" + +// ChannelCombinedPhrases - The full transcript per channel. +type ChannelCombinedPhrases struct { + // REQUIRED; The complete transcribed text for the channel. + Text *string + + // The 0-based channel index. Only present if channel separation is enabled. + Channel *int32 +} + +type TranscribeRequest struct { + // REQUIRED; The content of the audio file to be transcribed. The audio file must be shorter than 2 hours in audio duration + // and smaller than 250 MB in size. + Audio streaming.MultipartContent + + // Metadata for a transcription request. This field contains a JSON-serialized object of type `TranscribeDefinition`. + Options *TranscriptionOptions +} + +// TranscribedPhrase - A transcribed phrase. +type TranscribedPhrase struct { + // REQUIRED; The confidence value for the phrase. + Confidence *float32 + + // REQUIRED; The duration of the phrase in milliseconds. + DurationMilliseconds *int32 + + // REQUIRED; The start offset of the phrase in milliseconds. + OffsetMilliseconds *int32 + + // REQUIRED; The transcribed text of the phrase. + Text *string + + // The 0-based channel index. Only present if channel separation is enabled. + Channel *int32 + + // The locale of the phrase. + Locale *string + + // A unique integer number that is assigned to each speaker detected in the audio without particular order. Only present if + // speaker diarization is enabled. + Speaker *int32 + + // The words that make up the phrase. Only present if word-level timestamps are enabled. + Words []*TranscribedWord +} + +// TranscribedWord - Time-stamped word in the display form. +type TranscribedWord struct { + // REQUIRED; The duration of the word in milliseconds. + DurationMilliseconds *int32 + + // REQUIRED; The start offset of the word in milliseconds. + OffsetMilliseconds *int32 + + // REQUIRED; The recognized word, including punctuation. + Text *string +} + +// TranscriptionDiarizationOptions - The Speaker Identification settings. Diarization settings must be specified to enable +// speaker identification. +type TranscriptionDiarizationOptions struct { + // Gets or sets a value indicating whether speaker diarization is enabled. + Enabled *bool + + // Gets or sets a hint for the maximum number of speakers for diarization. Must be greater than 1 and less than 36. + MaxSpeakers *int32 +} + +// TranscriptionOptions - Metadata for a transcription request. +type TranscriptionOptions struct { + // The 0-based indices of the channels to be transcribed separately. If not specified, multiple channels are merged and transcribed + // jointly. Only up to two channels are supported. + ActiveChannels []*int32 + + // Mode of diarization. + DiarizationOptions *TranscriptionDiarizationOptions + + // A list of possible locales for the transcription. If not specified, the locale of the speech in the audio is detected automatically + // from all supported locales. + Locales []*string + + // Maps some or all candidate locales to a model URI to be used for transcription. If no mapping is given, the default model + // for the locale is used. + Models map[string]*string + + // Mode of profanity filtering. + ProfanityFilterMode *ProfanityFilterMode +} + +// TranscriptionResult - The result of the transcribe operation. +type TranscriptionResult struct { + // REQUIRED; The full transcript for each channel. + CombinedPhrases []*ChannelCombinedPhrases + + // REQUIRED; The duration of the audio in milliseconds. + DurationMilliseconds *int32 + + // REQUIRED; The transcription results segmented into phrases. + Phrases []*TranscribedPhrase +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/models_serde.go b/sdk/ai/azspeechtranscription/azspeechtranscription/models_serde.go new file mode 100644 index 000000000000..0870d6aaf321 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/models_serde.go @@ -0,0 +1,283 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechtranscription + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type ChannelCombinedPhrases. +func (c ChannelCombinedPhrases) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "channel", c.Channel) + populate(objectMap, "text", c.Text) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ChannelCombinedPhrases. +func (c *ChannelCombinedPhrases) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "channel": + err = unpopulate(val, "Channel", &c.Channel) + delete(rawMsg, key) + case "text": + err = unpopulate(val, "Text", &c.Text) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// toMultipartFormData converts TranscribeRequest to multipart/form data. +func (t TranscribeRequest) toMultipartFormData() (map[string]any, error) { + objectMap := make(map[string]any) + objectMap["audio"] = t.Audio + if t.Options != nil { + if err := populateMultipartJSON(objectMap, "definition", *t.Options); err != nil { + return nil, err + } + } + return objectMap, nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscribedPhrase. +func (t TranscribedPhrase) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "channel", t.Channel) + populate(objectMap, "confidence", t.Confidence) + populate(objectMap, "durationMilliseconds", t.DurationMilliseconds) + populate(objectMap, "locale", t.Locale) + populate(objectMap, "offsetMilliseconds", t.OffsetMilliseconds) + populate(objectMap, "speaker", t.Speaker) + populate(objectMap, "text", t.Text) + populate(objectMap, "words", t.Words) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscribedPhrase. +func (t *TranscribedPhrase) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "channel": + err = unpopulate(val, "Channel", &t.Channel) + delete(rawMsg, key) + case "confidence": + err = unpopulate(val, "Confidence", &t.Confidence) + delete(rawMsg, key) + case "durationMilliseconds": + err = unpopulate(val, "DurationMilliseconds", &t.DurationMilliseconds) + delete(rawMsg, key) + case "locale": + err = unpopulate(val, "Locale", &t.Locale) + delete(rawMsg, key) + case "offsetMilliseconds": + err = unpopulate(val, "OffsetMilliseconds", &t.OffsetMilliseconds) + delete(rawMsg, key) + case "speaker": + err = unpopulate(val, "Speaker", &t.Speaker) + delete(rawMsg, key) + case "text": + err = unpopulate(val, "Text", &t.Text) + delete(rawMsg, key) + case "words": + err = unpopulate(val, "Words", &t.Words) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscribedWord. +func (t TranscribedWord) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "durationMilliseconds", t.DurationMilliseconds) + populate(objectMap, "offsetMilliseconds", t.OffsetMilliseconds) + populate(objectMap, "text", t.Text) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscribedWord. +func (t *TranscribedWord) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "durationMilliseconds": + err = unpopulate(val, "DurationMilliseconds", &t.DurationMilliseconds) + delete(rawMsg, key) + case "offsetMilliseconds": + err = unpopulate(val, "OffsetMilliseconds", &t.OffsetMilliseconds) + delete(rawMsg, key) + case "text": + err = unpopulate(val, "Text", &t.Text) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscriptionDiarizationOptions. +func (t TranscriptionDiarizationOptions) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "enabled", t.Enabled) + populate(objectMap, "maxSpeakers", t.MaxSpeakers) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscriptionDiarizationOptions. +func (t *TranscriptionDiarizationOptions) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "enabled": + err = unpopulate(val, "Enabled", &t.Enabled) + delete(rawMsg, key) + case "maxSpeakers": + err = unpopulate(val, "MaxSpeakers", &t.MaxSpeakers) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscriptionOptions. +func (t TranscriptionOptions) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "channels", t.ActiveChannels) + populate(objectMap, "diarization", t.DiarizationOptions) + populate(objectMap, "locales", t.Locales) + populate(objectMap, "models", t.Models) + populate(objectMap, "profanityFilterMode", t.ProfanityFilterMode) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscriptionOptions. +func (t *TranscriptionOptions) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "channels": + err = unpopulate(val, "ActiveChannels", &t.ActiveChannels) + delete(rawMsg, key) + case "diarization": + err = unpopulate(val, "DiarizationOptions", &t.DiarizationOptions) + delete(rawMsg, key) + case "locales": + err = unpopulate(val, "Locales", &t.Locales) + delete(rawMsg, key) + case "models": + err = unpopulate(val, "Models", &t.Models) + delete(rawMsg, key) + case "profanityFilterMode": + err = unpopulate(val, "ProfanityFilterMode", &t.ProfanityFilterMode) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type TranscriptionResult. +func (t TranscriptionResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "combinedPhrases", t.CombinedPhrases) + populate(objectMap, "durationMilliseconds", t.DurationMilliseconds) + populate(objectMap, "phrases", t.Phrases) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type TranscriptionResult. +func (t *TranscriptionResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "combinedPhrases": + err = unpopulate(val, "CombinedPhrases", &t.CombinedPhrases) + delete(rawMsg, key) + case "durationMilliseconds": + err = unpopulate(val, "DurationMilliseconds", &t.DurationMilliseconds) + delete(rawMsg, key) + case "phrases": + err = unpopulate(val, "Phrases", &t.Phrases) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", t, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil || string(data) == "null" { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} + +func populateMultipartJSON(m map[string]any, k string, v any) error { + data, err := json.Marshal(v) + if err != nil { + return err + } + m[k] = data + return nil +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/options.go b/sdk/ai/azspeechtranscription/azspeechtranscription/options.go new file mode 100644 index 000000000000..429ba197eaf3 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/options.go @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechtranscription + +// TranscriptionClientTranscribeOptions contains the optional parameters for the TranscriptionClient.Transcribe method. +type TranscriptionClientTranscribeOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/responses.go b/sdk/ai/azspeechtranscription/azspeechtranscription/responses.go new file mode 100644 index 000000000000..9c9ba30702ee --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/responses.go @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechtranscription + +// TranscriptionClientTranscribeResponse contains the response from method TranscriptionClient.Transcribe. +type TranscriptionClientTranscribeResponse struct { + // The result of the transcribe operation. + TranscriptionResult +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/transcription_client.go b/sdk/ai/azspeechtranscription/azspeechtranscription/transcription_client.go new file mode 100644 index 000000000000..4be98874a4ee --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/transcription_client.go @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT. + +package azspeechtranscription + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" +) + +// TranscriptionClient contains the methods for the Transcription group. +// Don't use this type directly, use a constructor function instead. +type TranscriptionClient struct { + internal *azcore.Client + endpoint string +} + +// Transcribe - Transcribes the provided audio stream. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2024-11-15 +// - body - The body of the multipart request. +// - options - TranscriptionClientTranscribeOptions contains the optional parameters for the TranscriptionClient.Transcribe +// method. +func (client *TranscriptionClient) Transcribe(ctx context.Context, body TranscribeRequest, options *TranscriptionClientTranscribeOptions) (TranscriptionClientTranscribeResponse, error) { + var err error + const operationName = "TranscriptionClient.Transcribe" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.transcribeCreateRequest(ctx, body, options) + if err != nil { + return TranscriptionClientTranscribeResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return TranscriptionClientTranscribeResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return TranscriptionClientTranscribeResponse{}, err + } + resp, err := client.transcribeHandleResponse(httpResp) + return resp, err +} + +// transcribeCreateRequest creates the Transcribe request. +func (client *TranscriptionClient) transcribeCreateRequest(ctx context.Context, body TranscribeRequest, _ *TranscriptionClientTranscribeOptions) (*policy.Request, error) { + host := "{endpoint}/speechtotext" + host = strings.ReplaceAll(host, "{endpoint}", client.endpoint) + urlPath := "/transcriptions:transcribe" + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(host, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2024-11-15") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + formData, err := body.toMultipartFormData() + if err != nil { + return nil, err + } + if err := runtime.SetMultipartFormData(req, formData); err != nil { + return nil, err + } + return req, nil +} + +// transcribeHandleResponse handles the Transcribe response. +func (client *TranscriptionClient) transcribeHandleResponse(resp *http.Response) (TranscriptionClientTranscribeResponse, error) { + result := TranscriptionClientTranscribeResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.TranscriptionResult); err != nil { + return TranscriptionClientTranscribeResponse{}, err + } + return result, nil +} diff --git a/sdk/ai/azspeechtranscription/azspeechtranscription/tsp-location.yaml b/sdk/ai/azspeechtranscription/azspeechtranscription/tsp-location.yaml new file mode 100644 index 000000000000..b410f14d39d7 --- /dev/null +++ b/sdk/ai/azspeechtranscription/azspeechtranscription/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/cognitiveservices/Speech.Transcription +commit: 42d832f4bd16b04dd3cb124ca3e8dfaef1211bc2 +repo: Azure/azure-rest-api-specs +additionalDirectories: