Amplify Gen 2 Predictions transcribe set up

0

Hi everyone,

I am trying to set up amplify Predictions transcribe in my react native app and I keep getting a Transcription error: [NoRegion: Missing region.] but i can't seem to find where to add that info. I looked a lot in the documentation for gen 2 and no luck

This is my set up so far:

backend.ts

import { defineBackend } from "@aws-amplify/backend";
import { auth } from "./auth/resource";
import { data } from "./data/resource";
import { Stack } from "aws-cdk-lib";
import { PolicyStatement } from "aws-cdk-lib/aws-iam";

const backend = defineBackend({
  auth,
  data,
});

// Configure a policy for the required use case.
// The actions included below cover all supported ML capabilities
backend.auth.resources.unauthenticatedUserIamRole.addToPrincipalPolicy(
  new PolicyStatement({
    actions: [
      "translate:TranslateText",
      "polly:SynthesizeSpeech",
      "transcribe:StartStreamTranscriptionWebSocket",
    ],
    resources: ["*"],
  })
);

backend.addOutput({
  custom: {
    Predictions: {
      convert: {
        translateText: {
          defaults: {
            sourceLanguage: "en",
            targetLanguage: "es",
          },
          proxy: false,
          region: Stack.of(backend.auth.resources.unauthenticatedUserIamRole)
            .region,
        },
        transcription: {
          defaults: {
            language: "en-US",
          },
          proxy: false,
          region: Stack.of(backend.auth.resources.unauthenticatedUserIamRole)
            .region,
        },
      },
    },
  },
});

How I am using it:

  const transcribeAudio = async (audioBytes) => {
    try {
      const { transcription } = await Predictions.convert({
        region: "us-east-1",
        transcription: {
          source: {
            bytes: audioBytes,
          },
        },
      });
      console.log("Transcription:", transcription);
      // Handle the transcription result (e.g., set it to state, display it, etc.)
    } catch (error) {
      console.error("Transcription error:", error);
    }
  };

Any help would be very much appreciated thank you so much

Pedro-G
已提问 1 个月前48 查看次数
1 回答
0

Hi. I didn't test it with react native, but with React , this one worked for me

   const createTranscribeClient = () => {
        transcribeClient = new TranscribeStreamingClient({
            region: props.region,
            credentials: {
                accessKeyId: props.accessKeyId,
                secretAccessKey: props.secretAccessKey,
                sessionToken: props.sessionToken
            },
        });
    };
AWS
Mi_Sha
已回答 1 个月前
  • Thank you MI Sha, I appropriate your answer, that could work. After many different failed tests I decided to revert back to Gen 1. Gen 2 documentation is Terrible. I fell like the amplify team is trying really hard to make amplify better but whoever is in charge of making the documentation is letting the team down big time.

    The Amplify Documentation 1 or 2 year ago was really good, then they changed the UI it got worse, and now gen 2 is even worse. Oh well I'll work with gen 1 until gen 2 is more established.

    Again thank you for you comment I appreciate it a lot

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则