Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .doc_gen/metadata/dynamodb_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ dynamodb_Scenario_GettingStartedMovies:
- sdk_version: 3
github: php/example_code/dynamodb
excerpts:
- description:
- description: Because this example uses supporting files, be sure to <ulink url="https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/php/README.md#prerequisites">read the guidance</ulink> in the PHP examples README.md file.
snippet_tags:
- php.example_code.dynamodb.basics.scenario
Python:
Expand Down
38 changes: 2 additions & 36 deletions .doc_gen/metadata/transcribe-streaming_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ transcribe-streaming_StartMedicalStreamTranscription:
- transcribe.java-medical-streaming-demo
services:
transcribe-streaming: {StartMedicalStreamTranscription}
transcribe-streaming_Scenario_StreamEvents_File:
title: Generate a transcription of a file using an &AWS; SDK
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
Expand All @@ -58,39 +58,5 @@ transcribe-streaming_Scenario_StreamEvents_File:
snippet_tags:
- swift.transcribe-streaming.all
- swift.transcribe-streaming.transcribeerror
Java:
versions:
- sdk_version: 2
github: javav2/example_code/transcribe-streaming
sdkguide:
excerpts:
- description:
snippet_tags:
- transcribe.java-streaming-demo-file.main
C++:
versions:
- sdk_version: 1
github: cpp/example_code/transcribe-streaming
excerpts:
- description:
snippet_tags:
- transcribe.cpp.stream_transcription_async.code
services:
transcribe-streaming: {StartStreamTranscription}
transcribe-streaming_Scenario_StreamEvents_Microphone:
title: Generate a transcription from a microphone using an &AWS; SDK
title_abbrev: Transcribe audio from a microphone
synopsis: generate a transcription from a microphone using &TSC; streaming.
category: Scenarios
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/transcribe-streaming
sdkguide:
excerpts:
- description:
snippet_tags:
- transcribe.java-streaming-demo
services:
transcribe-streaming: {StartStreamTranscription}
21 changes: 1 addition & 20 deletions cpp/example_code/transcribe-streaming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ Code excerpts that show you how to call individual service functions.

- [StartStreamTranscription](get_transcript.cpp#L28)

### Scenarios

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

- [Transcribe an audio file](get_transcript.cpp)


<!--custom.examples.start-->
<!--custom.examples.end-->
Expand All @@ -76,18 +69,6 @@ folder.



#### 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_File.start-->
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_File.end-->


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

### Tests

⚠ Running tests might result in charges to your AWS account.
Expand Down Expand Up @@ -118,4 +99,4 @@ This example shows you how to generate a transcription of a source audio file us

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

SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: Apache-2.0
36 changes: 2 additions & 34 deletions javav2/example_code/transcribe-streaming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav
Code excerpts that show you how to call individual service functions.

- [StartMedicalStreamTranscription](src/main/java/com/amazonaws/transcribestreaming/TranscribeMedicalStreamingDemoApp.java#L25)
- [StartStreamTranscription](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoApp.java#L36)

### Scenarios

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

- [Transcribe an audio file](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoFile.java)
- [Transcribe audio from a microphone](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoApp.java)
- [StartStreamTranscription](src/main/java/com/amazonaws/transcribestreaming/TranscribeStreamingDemoApp.java#L26)


<!--custom.examples.start-->
Expand All @@ -58,30 +50,6 @@ functions within the same service.



#### 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_File.start-->
<!--custom.scenario_prereqs.transcribe-streaming_Scenario_StreamEvents_File.end-->


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

#### Transcribe audio from a microphone

This example shows you how to generate a transcription from a microphone using Amazon Transcribe streaming.


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


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

### Tests

⚠ Running tests might result in charges to your AWS account.
Expand All @@ -108,4 +76,4 @@ in the `javav2` folder.

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

SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,8 @@
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.transcribestreaming.TranscribeStreamingAsyncClient;
import software.amazon.awssdk.services.transcribestreaming.model.*;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UncheckedIOException;
import javax.sound.sampled.*;
import java.io.*;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.List;
Expand All @@ -38,7 +28,7 @@ public class TranscribeStreamingDemoApp {
private static final Region REGION = Region.US_EAST_1;
private static TranscribeStreamingAsyncClient client;

public static void main(String[] args)
public static void main(String args[])
throws URISyntaxException, ExecutionException, InterruptedException, LineUnavailableException {

client = TranscribeStreamingAsyncClient.builder()
Expand Down Expand Up @@ -95,7 +85,7 @@ private static StartStreamTranscriptionResponseHandler getResponseHandler() {
System.out.println(e.getMessage());
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
System.out.println("Error Occurred: " + sw);
System.out.println("Error Occurred: " + sw.toString());
})
.onComplete(() -> {
System.out.println("=== All records stream successfully ===");
Expand All @@ -111,10 +101,19 @@ private static StartStreamTranscriptionResponseHandler getResponseHandler() {
.build();
}


private InputStream getStreamFromFile(String audioFileName) {
try {
File inputFile = new File(getClass().getClassLoader().getResource(audioFileName).getFile());
InputStream audioStream = new FileInputStream(inputFile);
return audioStream;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}

private static class AudioStreamPublisher implements Publisher<AudioStream> {
private static Subscription currentSubscription;
private final InputStream inputStream;
private static Subscription currentSubscription;

private AudioStreamPublisher(InputStream inputStream) {
this.inputStream = inputStream;
Expand All @@ -123,22 +122,22 @@ private AudioStreamPublisher(InputStream inputStream) {
@Override
public void subscribe(Subscriber<? super AudioStream> s) {

if (currentSubscription == null) {
currentSubscription = new SubscriptionImpl(s, inputStream);
if (this.currentSubscription == null) {
this.currentSubscription = new SubscriptionImpl(s, inputStream);
} else {
currentSubscription.cancel();
currentSubscription = new SubscriptionImpl(s, inputStream);
this.currentSubscription.cancel();
this.currentSubscription = new SubscriptionImpl(s, inputStream);
}
s.onSubscribe(currentSubscription);
}
}

public static class SubscriptionImpl implements Subscription {
private static final int CHUNK_SIZE_IN_BYTES = 1024;
private static final int CHUNK_SIZE_IN_BYTES = 1024 * 1;
private final Subscriber<? super AudioStream> subscriber;
private final InputStream inputStream;
private final ExecutorService executor = Executors.newFixedThreadPool(1);
private final AtomicLong demand = new AtomicLong(0);
private ExecutorService executor = Executors.newFixedThreadPool(1);
private AtomicLong demand = new AtomicLong(0);

SubscriptionImpl(Subscriber<? super AudioStream> s, InputStream inputStream) {
this.subscriber = s;
Expand Down
59 changes: 56 additions & 3 deletions php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,75 @@ Cross-service examples are located in the [*cross-services folder*](cross_servic
* 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).

## Prerequisites

### Prerequisites
To run these code examples, you need:

* [PHP](https://www.php.net/) version 8.1 or higher
* [Composer](https://getcomposer.org) for dependency management
* [PHPUnit](https://phpunit.de/) for unit testing
* The [AWS SDK for PHP](https://aws.amazon.com/sdk-for-php/)
* [AWS credentials](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html) set up

For more information, see [Getting Started](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_index.html) in the AWS SDK for PHP Developer Guide.

## Set up the examples

Some examples require supporting files from the GitHub repository in addition to the AWS SDK for PHP. For these examples:

1. Clone, fork, or download the entire [aws-doc-sdk-examples repository](https://github.com/awsdocs/aws-doc-sdk-examples) from GitHub.

You need the entire repository, not just individual files, so supporting files can be accessed by the examples.

2. Install dependencies

From the directory that contains the composer.json file for the example, run:
```bash
composer install
```

3. Run examples from within the repository structure and from the directory that contains the initiating code

Run examples from within the cloned directory structure to ensure access to supporting files.

## Run the examples

By default, these code examples run using the default AWS credential provider chain, which includes using the AWS shared credentials and config files with a `default` profile.
For more information, about using AWS shared files and the `default` profile, see [Using shared config and credentials files to globally configure AWS SDKs and tools](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) in the *AWS SDKs and Tools
Reference Guide*.

Important: Running these code examples might result in charges to the AWS account associated with the AWS credentials being used.

Many examples include a `Runner.php` file to abstract the logic from running the code. From any example directory with a Runner.php file, run:

```bash
php Runner.php
```

---------

## Prerequisites
To run or test these code examples, you need the following:

- [PHP](https://www.php.net/) version 8.1 or higher
- [Composer](https://getcomposer.org), for dependency management
- [PHPUnit](https://phpunit.de/), for unit testing
- The [AWS SDK for PHP](https://aws.amazon.com/sdk-for-php/)
- [AWS credentials](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html) set up
- For examples that use supporting files that are available only in the GitHub repository
and not available for installation by Composer, you need to
- clone, fork, or download a zip of the entire [aws-doc-sdk-examples repository](https://github.com/awsdocs/aws-doc-sdk-examples) from GitHub.
You want the entire repository, not just indvidual files, so supporting files can be accessed by the examples.
- Run the example from within the directory structure and from within the directory that contains the composer.json file.
- Install the dependencies and configuration settings with Composer.

For more information, see [Getting Started](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_index.html) in the *AWS SDK for PHP Developer Guide*.

## Run the code

By default, these code examples run using the default AWS credential provider chain, which includes using an AWS shared credentials file and profiles.
For more information, see [Using the AWS Credentials File and Credential Profiles](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials_profiles.html) in the *AWS SDK for PHP Developer Guide*.
By default, these code examples run using the default AWS credential provider chain, which includes using the AWS shared credentials and config files with a `default` profile.
For more information, about using AWS shared files and the `default` profile, see [Using shared config and credentials files to globally configure AWS SDKs and tools](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) in the *AWS SDKs and Tools
Reference Guide*.

Running these code examples might result in charges to the AWS account that is associated with the AWS credentials being used.

Expand Down
4 changes: 1 addition & 3 deletions php/example_code/dynamodb/DynamoDBService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class DynamoDBService extends AWSServiceClass
public function __construct(
DynamoDbClient $client = null,
string $region = 'us-west-2',
string $version = 'latest',
string $profile = 'default'
string $version = 'latest'
) {
if (gettype($client) == DynamoDbClient::class) {
$this->dynamoDbClient = $client;
Expand All @@ -27,7 +26,6 @@ public function __construct(
$this->dynamoDbClient = new DynamoDbClient([
'region' => $region,
'version' => $version,
'profile' => $profile,
'http' => [
'verify' => false,
],
Expand Down
12 changes: 6 additions & 6 deletions php/example_code/dynamodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ Code examples that show you how to perform the essential operations within a ser

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

- [BatchExecuteStatement](DynamoDBService.php#L319)
- [BatchWriteItem](DynamoDBService.php#L201)
- [BatchExecuteStatement](DynamoDBService.php#L317)
- [BatchWriteItem](DynamoDBService.php#L199)
- [CreateTable](dynamodb_basics/GettingStartedWithDynamoDB.php#L52)
- [DeleteItem](dynamodb_basics/GettingStartedWithDynamoDB.php#L148)
- [DeleteTable](DynamoDBService.php#L84)
- [ExecuteStatement](DynamoDBService.php#L263)
- [DeleteTable](DynamoDBService.php#L82)
- [ExecuteStatement](DynamoDBService.php#L261)
- [GetItem](dynamodb_basics/GettingStartedWithDynamoDB.php#L131)
- [ListTables](DynamoDBService.php#L64)
- [ListTables](DynamoDBService.php#L62)
- [PutItem](dynamodb_basics/GettingStartedWithDynamoDB.php#L67)
- [Query](dynamodb_basics/GettingStartedWithDynamoDB.php#L158)
- [Scan](dynamodb_basics/GettingStartedWithDynamoDB.php#L178)
Expand Down Expand Up @@ -164,4 +164,4 @@ in the `php` folder.

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

SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: Apache-2.0
2 changes: 1 addition & 1 deletion php/example_code/dynamodb/dynamodb_basics/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DynamoDb\Basics\GettingStartedWithDynamoDB;

include "vendor\autoload.php";
include "vendor/autoload.php";

include "GettingStartedWithDynamoDB.php";

Expand Down
10 changes: 5 additions & 5 deletions php/example_code/dynamodb/dynamodb_basics/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"guzzlehttp/guzzle": "^7.0"
},
"autoload": {
"psr-0": {
"": "*"
},
"files": [
"../../aws_utilities/TestableReadline.php",
"../../aws_utilities/LoadMovieData.php"
],
"psr-4": {
"DynamoDb\\": "../../dynamodb/",
"DynamoDb\\Basics\\": "../../dynamodb/dynamodb_basics",
"AwsUtilities\\": "../../aws_utilities"
},
"files": ["../../aws_utilities/TestableReadline.php"]
}
}
}
Loading
Loading