aws-doc-sdk-examples icon indicating copy to clipboard operation
aws-doc-sdk-examples copied to clipboard

Refactoring and fixing various issues with the transcribe-streaming-app

Open PlasmaShine opened this issue 2 years ago • 1 comments

aws-doc-sdk-examples Pull Request

Thank you for making a submission to the aws-doc-sdk-examples repository. For more information about submitting pull requests to this repository, see Guidelines for contributing.

I'm resolving an issue with an existing code example

  • Adds Webpack 5 support
  • Updates dependencies to latest versions
  • Cleans up UI
  • Adds all currently supported languages both for streaming and translation
  • Fixes bug that causes the closure of the web socket in the case of an invalid audio chunk size
  • Makes the README a bit clearer
  • Refactors code to separate out concerns

Confirm you have met the following minimum requirements:


Open source license adherence

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

PlasmaShine avatar Sep 12 '22 09:09 PlasmaShine

index.js is reported as conflicting, but in fact it should not be. I refactored that file and the existing one should be completely replaced by the new one.

PlasmaShine avatar Sep 12 '22 09:09 PlasmaShine

Hey @PlasmaShine . When I run npm run build, I get several errors from webpack. Do you get the same?


> [email protected] build
> webpack --config ./webpack.config.cjs

asset main.js 5.18 MiB [emitted] (name: main)
orphan modules 598 KiB [orphan] 248 modules
runtime modules 937 bytes 4 modules
modules by path ./node_modules/ 1.69 MiB
  modules by path ./node_modules/@aws-sdk/ 1.44 MiB 211 modules
  modules by path ./node_modules/@aws-crypto/ 136 KiB 30 modules
  modules by path ./node_modules/fast-xml-parser/src/*.js 43.2 KiB 9 modules
  modules by path ./node_modules/entities/lib/ 41.9 KiB 8 modules
  modules by path ./node_modules/uuid/dist/esm-browser/*.js 3.24 KiB 5 modules
  + 2 modules
modules by path ./src/ 12 KiB
  ./src/index.js 3.52 KiB [built] [code generated]
  ./src/libs/transcribeClient.js 3.45 KiB [built] [code generated]
  ./src/libs/translateClient.js 2.22 KiB [built] [code generated]
  ./src/libs/emailClient.js 2.26 KiB [built] [code generated]
  ./src/libs/awsID.js 574 bytes [built] [code generated]

ERROR in ./node_modules/@aws-crypto/util/build/convertToBuffer.js 8:22-28
Module not found: Error: Can't resolve 'buffer' in '/Users/corepyle/Documents/teams/awsdocs/aws-doc-sdk-examples/javascriptv3/example_code/cross-services/transcribe-streaming-app/node_modules/@aws-crypto/util/build'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
        - install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "buffer": false }
 @ ./node_modules/@aws-crypto/util/build/index.js 6:24-52
 @ ./node_modules/@aws-crypto/sha256-browser/build/webCryptoSha256.js 4:13-40
 @ ./node_modules/@aws-crypto/sha256-browser/build/index.js 8:24-52
 @ ./node_modules/@aws-sdk/client-translate/dist-es/runtimeConfig.browser.js 3:0-52 25:130-136
 @ ./node_modules/@aws-sdk/client-translate/dist-es/TranslateClient.js 11:0-73 16:24-42
 @ ./node_modules/@aws-sdk/client-translate/dist-es/index.js 2:0-34 2:0-34
 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28
 @ ./src/index.js 17:0-61 73:28-67

ERROR in ./node_modules/@aws-sdk/middleware-recursion-detection/dist-es/index.js 17:31-38
Module not found: Error: Can't resolve 'process/browser' in '/Users/corepyle/Documents/teams/awsdocs/aws-doc-sdk-examples/javascriptv3/example_code/cross-services/transcribe-streaming-app/node_modules/@aws-sdk/middleware-recursion-detection/dist-es'
 @ ./node_modules/@aws-sdk/client-translate/dist-es/TranslateClient.js 6:0-86 29:34-61
 @ ./node_modules/@aws-sdk/client-translate/dist-es/index.js 2:0-34 2:0-34
 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28
 @ ./src/index.js 17:0-61 73:28-67

ERROR in ./node_modules/@aws-sdk/smithy-client/dist-es/emitWarningIfUnsupportedVersion.js 5:8-15
Module not found: Error: Can't resolve 'process/browser' in '/Users/corepyle/Documents/teams/awsdocs/aws-doc-sdk-examples/javascriptv3/example_code/cross-services/transcribe-streaming-app/node_modules/@aws-sdk/smithy-client/dist-es'
 @ ./node_modules/@aws-sdk/smithy-client/dist-es/index.js 7:0-50 7:0-50
 @ ./node_modules/@aws-sdk/client-translate/dist-es/TranslateClient.js 10:0-61 38:2-10
 @ ./node_modules/@aws-sdk/client-translate/dist-es/index.js 2:0-34 2:0-34
 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28
 @ ./src/index.js 17:0-61 73:28-67

ERROR in ./src/libs/transcribeClient.js 14:0-49
Module not found: Error: Can't resolve 'microphone-stream' in '/Users/corepyle/Documents/teams/awsdocs/aws-doc-sdk-examples/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs'
 @ ./src/index.js 16:0-63 41:10-41 58:2-32

ERROR in ./src/libs/transcribeClient.js 16:0-32
Module not found: Error: Can't resolve 'buffer' in '/Users/corepyle/Documents/teams/awsdocs/aws-doc-sdk-examples/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
        - install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "buffer": false }
 @ ./src/index.js 16:0-63 41:10-41 58:2-32

ERROR in ./node_modules/@aws-crypto/util/build/convertToBuffer.js
Cannot read properties of undefined (reading 'module')
 @ ./node_modules/@aws-crypto/util/build/index.js 6:24-52
 @ ./node_modules/@aws-crypto/sha256-browser/build/webCryptoSha256.js 4:13-40
 @ ./node_modules/@aws-crypto/sha256-browser/build/index.js 8:24-52
 @ ./node_modules/@aws-sdk/client-translate/dist-es/runtimeConfig.browser.js 3:0-52 25:130-136
 @ ./node_modules/@aws-sdk/client-translate/dist-es/TranslateClient.js 11:0-73 16:24-42
 @ ./node_modules/@aws-sdk/client-translate/dist-es/index.js 2:0-34 2:0-34
 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28
 @ ./src/index.js 17:0-61 73:28-67

ERROR in ./node_modules/@aws-sdk/middleware-recursion-detection/dist-es/index.js
Cannot read properties of undefined (reading 'module')
 @ ./node_modules/@aws-sdk/client-translate/dist-es/TranslateClient.js 6:0-86 29:34-61
 @ ./node_modules/@aws-sdk/client-translate/dist-es/index.js 2:0-34 2:0-34
 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28
 @ ./src/index.js 17:0-61 73:28-67

ERROR in ./node_modules/@aws-sdk/smithy-client/dist-es/emitWarningIfUnsupportedVersion.js
Cannot read properties of undefined (reading 'module')
 @ ./node_modules/@aws-sdk/smithy-client/dist-es/index.js 7:0-50 7:0-50
 @ ./node_modules/@aws-sdk/client-translate/dist-es/TranslateClient.js 10:0-61 38:2-10
 @ ./node_modules/@aws-sdk/client-translate/dist-es/index.js 2:0-34 2:0-34
 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28
 @ ./src/index.js 17:0-61 73:28-67

8 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.74.0 compiled with 8 errors in 763 ms

cpyle0819 avatar Sep 26 '22 13:09 cpyle0819

Well, the principle I follow is that code that works together should live together, but to your point, I could create an id file containing all component ids. That way we both get what we want. How do you feel about it?

Sent from my iPhone

On Sep 26, 2022, at 22:24, Corey Pyle @.***> wrote:

 @cpyle0819 commented on this pull request.

In javascriptv3/example_code/cross-services/transcribe-streaming-app/src/index.js:

-// Helper function to encode PCM audio. -const pcmEncodeChunk = (chunk) => {

  • const input = MicrophoneStream.toRaw(chunk);
  • var offset = 0;
  • var buffer = new ArrayBuffer(input.length * 2);
  • var view = new DataView(buffer);
  • for (var i = 0; i < input.length; i++, offset += 2) {
  • var s = Math.max(-1, Math.min(1, input[i]));
  • view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true); +window.onRecordPress = () => {
  • let recordingButton = document.getElementById("record"); Agreed, there would not be a performance benefit. From a maintenance perspective thought it's easier to change an element id in 1 place rather than several.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

PlasmaShine avatar Sep 27 '22 00:09 PlasmaShine

Aaaaah! Now I remember! Webpack stopped packaging built in node modules a while ago so that’s why I had to add buffer, micstream etc to the packages json. But it is strange that I ran npm run build on local and did not get that stuff. Perhaps it’s the cache. Will add them back and submit again.

Sent from my iPhone

On Sep 26, 2022, at 22:56, Corey Pyle @.***> wrote:

 Hey @PlasmaShine . When I run npm run build, I get several errors from webpack. Do you get the same?

@.*** build webpack --config ./webpack.config.cjs

asset main.js 5.18 MiB [emitted] (name: main) orphan modules 598 KiB [orphan] 248 modules runtime modules 937 bytes 4 modules modules by path ./node_modules/ 1.69 MiB modules by path .@./ 1.44 MiB 211 modules modules by path .@./ 136 KiB 30 modules modules by path ./node_modules/fast-xml-parser/src/.js 43.2 KiB 9 modules modules by path ./node_modules/entities/lib/ 41.9 KiB 8 modules modules by path ./node_modules/uuid/dist/esm-browser/.js 3.24 KiB 5 modules

  • 2 modules modules by path ./src/ 12 KiB ./src/index.js 3.52 KiB [built] [code generated] ./src/libs/transcribeClient.js 3.45 KiB [built] [code generated] ./src/libs/translateClient.js 2.22 KiB [built] [code generated] ./src/libs/emailClient.js 2.26 KiB [built] [code generated] ./src/libs/awsID.js 574 bytes [built] [code generated]

ERROR in .@./util/build/convertToBuffer.js 8:22-28 Module not found: Error: Can't resolve 'buffer' in @./util/build'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }' - install 'buffer' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "buffer": false } @ .@./util/build/index.js 6:24-52 @ .@./sha256-browser/build/webCryptoSha256.js 4:13-40 @ .@./sha256-browser/build/index.js 8:24-52 @ .@./client-translate/dist-es/runtimeConfig.browser.js 3:0-52 25:130-136 @ .@./client-translate/dist-es/TranslateClient.js 11:0-73 16:24-42 @ .@./client-translate/dist-es/index.js 2:0-34 2:0-34 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28 @ ./src/index.js 17:0-61 73:28-67

ERROR in .@./middleware-recursion-detection/dist-es/index.js 17:31-38 Module not found: Error: Can't resolve 'process/browser' in @./middleware-recursion-detection/dist-es' @ .@./client-translate/dist-es/TranslateClient.js 6:0-86 29:34-61 @ .@./client-translate/dist-es/index.js 2:0-34 2:0-34 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28 @ ./src/index.js 17:0-61 73:28-67

ERROR in .@./smithy-client/dist-es/emitWarningIfUnsupportedVersion.js 5:8-15 Module not found: Error: Can't resolve 'process/browser' in @./smithy-client/dist-es' @ .@./smithy-client/dist-es/index.js 7:0-50 7:0-50 @ .@./client-translate/dist-es/TranslateClient.js 10:0-61 38:2-10 @ .@.***/client-translate/dist-es/index.js 2:0-34 2:0-34 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28 @ ./src/index.js 17:0-61 73:28-67

ERROR in ./src/libs/transcribeClient.js 14:0-49 Module not found: Error: Can't resolve 'microphone-stream' in '/Users/corepyle/Documents/teams/awsdocs/aws-doc-sdk-examples/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs' @ ./src/index.js 16:0-63 41:10-41 58:2-32

ERROR in ./src/libs/transcribeClient.js 16:0-32 Module not found: Error: Can't resolve 'buffer' in '/Users/corepyle/Documents/teams/awsdocs/aws-doc-sdk-examples/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }' - install 'buffer' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "buffer": false } @ ./src/index.js 16:0-63 41:10-41 58:2-32

ERROR in .@./util/build/convertToBuffer.js Cannot read properties of undefined (reading 'module') @ .@./util/build/index.js 6:24-52 @ .@./sha256-browser/build/webCryptoSha256.js 4:13-40 @ .@./sha256-browser/build/index.js 8:24-52 @ .@./client-translate/dist-es/runtimeConfig.browser.js 3:0-52 25:130-136 @ .@./client-translate/dist-es/TranslateClient.js 11:0-73 16:24-42 @ .@.***/client-translate/dist-es/index.js 2:0-34 2:0-34 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28 @ ./src/index.js 17:0-61 73:28-67

ERROR in .@./middleware-recursion-detection/dist-es/index.js Cannot read properties of undefined (reading 'module') @ .@./client-translate/dist-es/TranslateClient.js 6:0-86 29:34-61 @ .@.***/client-translate/dist-es/index.js 2:0-34 2:0-34 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28 @ ./src/index.js 17:0-61 73:28-67

ERROR in .@./smithy-client/dist-es/emitWarningIfUnsupportedVersion.js Cannot read properties of undefined (reading 'module') @ .@./smithy-client/dist-es/index.js 7:0-50 7:0-50 @ .@./client-translate/dist-es/TranslateClient.js 10:0-61 38:2-10 @ .@./client-translate/dist-es/index.js 2:0-34 2:0-34 @ ./src/libs/translateClient.js 13:0-82 48:8-28 55:13-28 @ ./src/index.js 17:0-61 73:28-67

8 errors have detailed information that is not shown. Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.74.0 compiled with 8 errors in 763 ms — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

PlasmaShine avatar Sep 27 '22 00:09 PlasmaShine

Hey @PlasmaShine , I've got the app up and running thanks to your latest changes. However, it doesn't seem like any data is being sent/received to Transcribe. Are you able to successfully record?

cpyle0819 avatar Sep 27 '22 12:09 cpyle0819