Skip to content

Commit da11d6b

Browse files
committed
feat: Initial commit
0 parents  commit da11d6b

File tree

126 files changed

+22036
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+22036
-0
lines changed

.cfignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git/
2+
node_modules/

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
node_modules/

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SPEECH_TO_TEXT_APIKEY=<COPY-YOUR-API-KEY-HERE>
2+
SPEECH_TO_TEXT_URL=https://us-south.speech-to-text.watson.cloud.ibm.com

.eslintrc.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es6": true,
6+
"node": true,
7+
"jest": true
8+
},
9+
"extends": [
10+
"eslint:recommended",
11+
"plugin:jest/recommended",
12+
"plugin:react/recommended"
13+
],
14+
"globals": {
15+
"Atomics": "readonly",
16+
"SharedArrayBuffer": "readonly",
17+
"page": true,
18+
"browser": true,
19+
"context": true,
20+
"jestPuppeteer": true
21+
},
22+
"parserOptions": {
23+
"ecmaFeatures": {
24+
"jsx": true
25+
},
26+
"ecmaVersion": 2018,
27+
"sourceType": "module"
28+
},
29+
"plugins": ["jest", "react", "react-hooks"],
30+
"rules": {
31+
"react-hooks/rules-of-hooks": "error",
32+
"react-hooks/exhaustive-deps": "warn"
33+
}
34+
}

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Dependencies
2+
.npm
3+
node_modules
4+
5+
# Config
6+
.next
7+
8+
# Misc
9+
.DS_Store
10+
*.env

.travis.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: node_js
2+
sudo: required
3+
node_js: 12
4+
cache:
5+
directories:
6+
- node_modules
7+
env:
8+
global:
9+
- BX_APP=speech-to-text-code-pattern
10+
- BX_API=https://api.ng.bluemix.net
11+
- BX_ORGANIZATION=WatsonPlatformServices
12+
- BX_SPACE=demos
13+
script:
14+
- npm run build
15+
- npm run test
16+
before_deploy:
17+
- npm install -g bx-blue-green
18+
deploy:
19+
- provider: script
20+
skip_cleanup: true
21+
script: bx-blue-green-travis
22+
on:
23+
branch: master
24+
repo: watson-developer-cloud/speech-to-text-code-pattern
25+
- provider: script
26+
skip_cleanup: true
27+
script: npx semantic-release

Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM node:12-alpine AS base
2+
WORKDIR /app
3+
4+
FROM base as build
5+
COPY ./package*.js* /app/
6+
RUN npm set progress=false && \
7+
npm config set depth 0 && \
8+
npm install
9+
10+
COPY ./config /app/config
11+
COPY ./public /app/public
12+
COPY ./src /app/src
13+
COPY ./test /app/test
14+
COPY ./*.js /app/
15+
16+
RUN npm run build
17+
RUN npm run test:components
18+
19+
FROM base as release
20+
21+
COPY --from=build /app/build /app/build
22+
COPY --from=build /app/config /app/config
23+
COPY --from=build /app/*.js* /app/
24+
25+
RUN npm install --only=prod
26+
27+
EXPOSE 5000
28+
CMD ["npm", "start"]

Dockerfile-tools

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ibmcom/ibmnode
2+
3+
ADD . /app
4+
5+
ENV NODE_ENV production
6+
ENV PORT 5000
7+
8+
EXPOSE 5000
9+
10+
WORKDIR /app
11+
12+
RUN npm install
13+
CMD ["/bin/bash"]
14+
15+
ARG bx_dev_user=root
16+
ARG bx_dev_userid=1000
17+
18+
RUN BX_DEV_USER=$bx_dev_user
19+
RUN BX_DEV_USERID=$bx_dev_userid
20+
RUN if [ "$bx_dev_user" != root ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi

README.md

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
<h1 align="center" style="border-bottom: none;">Speech to Text Code Pattern 🗣</h1>
2+
<h3 align="center">Sample React app for playing around with the Watson Speech to Text service.</h3>
3+
<p align="center">
4+
<a href="http://travis-ci.org/watson-developer-cloud/speech-to-text-code-pattern">
5+
<img alt="Travis" src="https://travis-ci.org/watson-developer-cloud/speech-to-text-code-pattern.svg?branch=master">
6+
</a>
7+
<a href="#badge">
8+
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
9+
</a>
10+
</p>
11+
</p>
12+
13+
**Demo:** https://speech-to-text-code-pattern.mybluemix.net/
14+
15+
## Flow
16+
17+
<p align="center">
18+
<img alt="architecture" width="600" src="./public/architecture.png">
19+
</p>
20+
21+
1. User supplies an audio input to the application (running locally, in the IBM Cloud or in IBM Cloud Pak for Data).
22+
1. The application sends the audio data to the Watson Speech to Text service through a [WebSocket connection](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-websockets).
23+
1. As the data is processed, the Speech to Text service returns information about extracted text and other metadata to the application to display.
24+
25+
## Prerequisites
26+
27+
1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).
28+
1. Download the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview).
29+
1. Create an instance of the Speech to Text service and get your credentials:
30+
- Go to the [Speech to Text](https://console.bluemix.net/catalog/services/speech-to-text) page in the IBM Cloud Catalog.
31+
- Log in to your IBM Cloud account.
32+
- Click **Create**.
33+
- Click **Show** to view the service credentials.
34+
- Copy the `apikey` value.
35+
- Copy the `url` value.
36+
37+
### Cloud Pak for Data
38+
39+
To use this code pattern with a Speech to Text instance provisioned on Cloud Pak for Data, you can use your CPD `username` and `password` credentials or an `access_token` to authenticate your requests. You also need the service `url` as described [here](https://cloud.ibm.com/apidocs/speech-to-text/speech-to-text-data#authentication).
40+
41+
Another important thing to note is that this code pattern assumes that you're using a **valid SSL certificate** for your CPD cluster. If not, you'll receive transcription errors. If you'd still like to use the app with an invalid certificate, you'll need to look up your browser-specific way to ignore these certificate errors. Do note that this is very insecure though!
42+
43+
## Configuring the application
44+
45+
Depending on where your service instance is you may have different ways to download the credentials file.
46+
47+
> Need more information? See the [authentication wiki](https://github.com/IBM/node-sdk-core/blob/master/AUTHENTICATION.md).
48+
49+
### Automatically
50+
51+
Copy the credential file to the application folder.
52+
53+
**Cloud Pak for Data**
54+
55+
<p align="center">
56+
<img alt="CPD" width="600" src="https://watson-developer-cloud.github.io/images/credentials-cpd.png">
57+
</p>
58+
59+
**Public Cloud**
60+
61+
<p align="center">
62+
<img alt="public" width="600" src="https://watson-developer-cloud.github.io/images/credentials-public.png">
63+
</p>
64+
65+
### Manually
66+
67+
1. In the application folder, copy the `.env.example` file and create a file called `.env`:
68+
69+
```
70+
cp .env.example .env
71+
```
72+
73+
2. Open the `.env` file and add the service credentials depending on your environment.
74+
75+
Example `.env` file that configures the `apikey` and `url` for a Speech to Text service instance hosted in the US South region:
76+
77+
```
78+
SPEECH_TO_TEXT_APIKEY=12345abcde
79+
SPEECH_TO_TEXT_URL=https://stream.watsonplatform.net/speech-to-text/api
80+
```
81+
82+
- **CPD using username and password:** If your service instance is running in Cloud Pak for Data and you want to use `username` and `password` credentials, add the following variables to the `.env` file.
83+
84+
```
85+
SPEECH_TO_TEXT_USERNAME=admin
86+
SPEECH_TO_TEXT_PASSWORD=password
87+
SPEECH_TO_TEXT_URL=https://{cpd-url}:{cpd-port}/speech-to-text/api
88+
```
89+
90+
- **CPD using access token:** If your service instance is running in Cloud Pak for Data and you want to use the `access_token` from the service instance detail page, add the following:
91+
92+
```
93+
SPEECH_TO_TEXT_BEARER_TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.ey...
94+
SPEECH_TO_TEXT_URL=https://{cpd-url}:{cpd-port}/speech-to-text/api
95+
```
96+
97+
## Running locally
98+
99+
1. Install the dependencies
100+
101+
```
102+
npm install
103+
```
104+
105+
1. Build the application
106+
107+
```
108+
npm run build
109+
```
110+
111+
1. Run the application
112+
113+
```
114+
npm run dev
115+
```
116+
117+
1. View the application in a browser at `localhost:3000`
118+
119+
## Deploying to IBM Cloud as a Cloud Foundry Application
120+
121+
Click on the button below to deploy this demo to the IBM Cloud.
122+
123+
[![Deploy to IBM Cloud](https://cloud.ibm.com/devops/setup/deploy/button.png)](https://cloud.ibm.com/devops/setup/deploy?repository=https://github.com/watson-developer-cloud/speech-to-text-code-pattern)
124+
125+
1. Build the application
126+
127+
```
128+
npm run build
129+
```
130+
131+
1. Login to IBM Cloud with the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview)
132+
133+
```
134+
ibmcloud login
135+
```
136+
137+
1. Target a Cloud Foundry organization and space.
138+
139+
```
140+
ibmcloud target --cf
141+
```
142+
143+
1. Edit the `manifest.yml` file. Change the **name** field to something unique. For example: `- name: my-app-name`.
144+
1. Deploy the application
145+
146+
```
147+
ibmcloud app push
148+
```
149+
150+
1. View the application online at the app URL, for example: https://my-app-name.mybluemix.net
151+
152+
## Tests
153+
154+
#### Unit tests
155+
156+
Run unit tests with:
157+
158+
```
159+
npm run test:components
160+
```
161+
162+
See the output for more info.
163+
164+
#### Integration tests
165+
166+
First you have to make sure your code is built:
167+
168+
```
169+
npm run build
170+
```
171+
172+
Then run integration tests with:
173+
174+
```
175+
npm run test:integration
176+
```
177+
178+
## Directory structure
179+
180+
```none
181+
.
182+
├── app.js // Express routes
183+
├── config // Express configuration
184+
│ ├── error-handler.js
185+
│ ├── express.js
186+
│ └── security.js
187+
├── package.json
188+
├── public // Static resources
189+
├── server.js // Entry point
190+
├── test // Tests
191+
└── src // React client
192+
└── index.js // App entry point
193+
```
194+
195+
## License
196+
197+
This sample code is licensed under the [MIT License](https://opensource.org/licenses/MIT).
198+
199+
## Open Source @ IBM
200+
201+
Find more open source projects on the [IBM Github Page](http://ibm.github.io/)

0 commit comments

Comments
 (0)