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

Predictions text to speech throws error related to ArrayBuffer (React Native) #11588

Closed
hoangtam101 opened this issue Jun 26, 2023 · 8 comments
Closed
Labels
bug Something isn't working duplicate If marked with duplicate, issue will be closed & original will be added for traceability Predictions Related to Predictions category React Native React Native related issue

Comments

@hoangtam101
Copy link

Hi everybody,

I trying to create an example using aws-amplify to handle text-to-speech.
So I follow the document: https://docs.amplify.aws/lib/predictions/text-speech/q/platform/react-native/#set-up-the-backend

Then I run the example I got the message [Error: FileReader.readAsArrayBuffer is not implemented]

Here is my code for calling Predictions to convert text to speech.
Predictions.convert({ textToSpeech: { source: { text: 'Hello. Text to speak', }, voiceId: 'Ivy', }, }) .then(result => {}) .catch(err => console.log({ err }));

Can anyone help me?

Thank a lot.

@nadetastic
Copy link
Member

Hi @hoangtam101 thank you for opening this issue - Question i have for you is, are you doing anything to consume the result from Predictions.convert()?

@hoangtam101
Copy link
Author

Hi @nadetastic For example I just want to code is work and log the result to know the data.
So the current code does not work, I still got an error message above.

Thanks,

@hoangtam101
Copy link
Author

Hello @nadetastic
Can you give me an example or code to run it success?

I stuck with it.
WARN Possible Unhandled Promise Rejection (id: 0): Error: FileReader.readAsArrayBuffer is not implemented

@nadetastic
Copy link
Member

@hoangtam101 I spent some time digging into this and found a potential problem that affects how Predictions.convert() for text-to-speech works in React Native. In short the library uses ArrayBuffer to create a blob from the response - and the issue is React Native doesn't support ArrayBuffer conversions very well.

Im transferring this over to the Javascript repo to better continue investigating this issue.

@nadetastic nadetastic transferred this issue from aws-amplify/docs Jul 6, 2023
@nadetastic nadetastic added investigating This issue is being investigated Predictions Related to Predictions category and removed amplify/js labels Jul 6, 2023
@nadetastic nadetastic changed the title Aws-amplify text to speech Predictions text to speech throws error related to ArrayBuffer (React Native) Jul 6, 2023
@cwomack cwomack added bug Something isn't working and removed investigating This issue is being investigated labels Jul 11, 2023
@nadetastic
Copy link
Member

Hi @hoangtam101 we've identified this as a bug with the library and are continuing to investigate a fix for this. In short, the implementation in place uses ArrayBuffer conversions which works as expected for web, however RN BlobManager doesn't supports ArrayBuffer conversions very well.

try {
const data = await this.pollyClient.send(synthesizeSpeechCommand);
const response = new Response(data.AudioStream as ReadableStream);
const arrayBuffer = await response.arrayBuffer();
const blob = new Blob([arrayBuffer], {
type: data.ContentType,
});
const url = URL.createObjectURL(blob);
return {
speech: { url },
audioStream: arrayBuffer,
text: input.textToSpeech.source.text,
} as TextToSpeechOutput;
} catch (err) {
return Promise.reject(err);
}
}

I'll update this issue once I have some additional info.

@kyokchyan
Copy link

Any updates on this issue with ArrayBuffer?

@Umoren
Copy link

Umoren commented Aug 2, 2023

I think there's a similar problem in React with the SpeechToText functionality.

async function startRecording() {
        console.log('start recording');
        audioBuffer.reset();

        window.navigator.mediaDevices.getUserMedia({ video: false, audio: true }).then((stream) => {
            const startMic = new mic();

            startMic.setStream(stream);
            startMic.on('data', (chunk) => { // error: process is not defined
                var raw = mic.toRaw(chunk);
                if (raw == null) {
                    return;
                }
                audioBuffer.addData(raw);

            });

            setRecording(true);
            setMicStream(startMic);
        });
}
Screenshot 2023-08-02 at 22 33 55

@cwomack cwomack added React Native React Native related issue duplicate If marked with duplicate, issue will be closed & original will be added for traceability labels May 24, 2024
@cwomack
Copy link
Member

cwomack commented May 24, 2024

Hello, @hoangtam101, @Umoren, and @kyokchyan 👋. Wanted to update this issue and let you all know that we'll be consolidating this into #13322 in order to better focus on a more general investigation into the support/bugs with Predictions and React Native in v5 of Amplify. If you have any additional context/feedback, feel free to comment on that issue and follow it for updates.

@cwomack cwomack closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate If marked with duplicate, issue will be closed & original will be added for traceability Predictions Related to Predictions category React Native React Native related issue
Projects
None yet
Development

No branches or pull requests

7 participants