Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Transcribe streaming example for Swift #7148

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .doc_gen/metadata/transcribe-streaming_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ transcribe-streaming_StartStreamTranscription:
- description:
snippet_tags:
- transcribe.cpp.stream_transcription_async.code
Swift:
versions:
- sdk_version: 1
github: swift/example_code/transcribe-streaming
excerpts:
- description:
snippet_tags:
- swift.transcribe-streaming.StartStreamTranscription
services:
transcribe-streaming: {StartStreamTranscription}
transcribe-streaming_StartMedicalStreamTranscription:
Expand All @@ -34,3 +42,21 @@ transcribe-streaming_StartMedicalStreamTranscription:
- transcribe.java-medical-streaming-demo
services:
transcribe-streaming: {StartMedicalStreamTranscription}
transcribe-streaming_Scenario_StreamEvents:
title: Generate a transcription of an audio stream using an &AWS; SDK
title_abbrev: Transcribe an audio file
synopsis: generate a transcription of a source audio file using &TSC; streaming.
category: Scenarios
languages:
Swift:
versions:
- sdk_version: 1
github: swift/example_code/transcribe-streaming
sdkguide:
excerpts:
- description: Use &TSC; streaming to transcribe the spoken language in an audio file.
snippet_tags:
- swift.transcribe-streaming.all
- swift.transcribe-streaming.transcribeerror
services:
transcribe-streaming: {StartStreamTranscription}
108 changes: 108 additions & 0 deletions swift/example_code/transcribe-streaming/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Amazon Transcribe Streaming code examples for the SDK for Swift

## Overview

Shows how to use the AWS SDK for Swift to work with Amazon Transcribe Streaming.

<!--custom.overview.start-->
<!--custom.overview.end-->

_Amazon Transcribe Streaming produces real-time transcriptions for your media content._

## ⚠ Important

* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/).
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).

<!--custom.important.start-->
<!--custom.important.end-->

## Code examples

### Prerequisites

For prerequisites, see the [README](../../README.md#Prerequisites) in the `swift` folder.


<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->

### Single actions

Code excerpts that show you how to call individual service functions.

- [StartStreamTranscription](transcribe-events/Sources/entry.swift#L145)

### Scenarios

Code examples that show you how to accomplish a specific task by calling multiple
functions within the same service.

- [Transcribe an audio file](transcribe-events/Sources/entry.swift)


<!--custom.examples.start-->
<!--custom.examples.end-->

## Run the examples

### Instructions

To build any of these examples from a terminal window, navigate into its
directory, then use the following command:

```
$ swift build
```

To build one of these examples in Xcode, navigate to the example's directory
(such as the `ListUsers` directory, to build that example). Then type `xed.`
to open the example directory in Xcode. You can then use standard Xcode build
and run commands.

<!--custom.instructions.start-->
<!--custom.instructions.end-->



#### Transcribe an audio file

This example shows you how to generate a transcription of a source audio file using Amazon Transcribe streaming.


<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents.start-->
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents.end-->


<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents.start-->
<!--custom.scenarios.transcribe-streaming_Scenario_StreamEvents.end-->

### Tests

⚠ Running tests might result in charges to your AWS account.


To find instructions for running these tests, see the [README](../../README.md#Tests)
in the `swift` folder.



<!--custom.tests.start-->
<!--custom.tests.end-->

## Additional resources

- [Amazon Transcribe Streaming Developer Guide](https://docs.aws.amazon.com/transcribe/latest/dg/streaming.html)
- [Amazon Transcribe Streaming API Reference](https://docs.aws.amazon.com/transcribe/latest/APIReference/Welcome.html)
- [SDK for Swift Amazon Transcribe Streaming reference](https://sdk.amazonaws.com/swift/api/awstranscribestreaming/latest/documentation/awstranscribestreaming)

<!--custom.resources.start-->
<!--custom.resources.end-->

---

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// swift-tools-version: 5.9
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//
// The swift-tools-version declares the minimum version of Swift required to
// build this package.

import PackageDescription

let package = Package(
name: "tsevents",
// Let Xcode know the minimum Apple platforms supported.
platforms: [
.macOS(.v13),
.iOS(.v15)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(
url: "https://github.com/awslabs/aws-sdk-swift",
from: "1.0.0"),
.package(
url: "https://github.com/apple/swift-argument-parser.git",
branch: "main"
)
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products
// from dependencies.
.executableTarget(
name: "tsevents",
dependencies: [
.product(name: "AWSTranscribeStreaming", package: "aws-sdk-swift"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources"),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// snippet-start:[swift.transcribe-streaming.transcribeerror]
/// Errors thrown by the example's functions.
enum TranscribeError: Error {
/// No transcription stream available.
case noTranscriptionStream
/// The source media file couldn't be read.
case readError

var errorDescription: String? {
switch self {
case .noTranscriptionStream:
return "No transcription stream returned by Amazon Transcribe."
case .readError:
return "Unable to read the source audio file."
}
}
}
// snippet-end:[swift.transcribe-streaming.transcribeerror]
Loading
Loading