Skip to content

Commit

Permalink
Merge pull request #3 from watson-developer-cloud/development
Browse files Browse the repository at this point in the history
Merge development into master
  • Loading branch information
lpatino10 authored Jan 24, 2020
2 parents 6f9c817 + df20dd5 commit a636d45
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let username = process.env.TEXT_TO_SPEECH_USERNAME;
let password = process.env.TEXT_TO_SPEECH_PASSWORD;

// On Cloud Foundry, we'll have a VCAP_SERVICES environment variable with credentials.
let vcapCredentials = vcapServices.getCredentials('speech_to_text');
let vcapCredentials = vcapServices.getCredentials('text_to_speech');

// Create appropriate token manager and client.
let client;
Expand Down
18 changes: 14 additions & 4 deletions src/components/ControlContainer/ControlContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {
Tile,
} from 'carbon-components-react';
import useDataApi from 'use-data-api';
import { sampleText } from '../../data/sampleText';

const VOICES_ENDPOINT = '/api/voices';

const mapVoicesToDropdownItems = voices =>
voices
.sort((voiceA, voiceB) => voiceA.description > voiceB.description)
.sort((voiceA, voiceB) =>
voiceA.description.localeCompare(voiceB.description),
)
.map(voice => {
const colonIndex = voice.description.indexOf(':');
const voicePersonName = voice.description.substring(0, colonIndex);
Expand Down Expand Up @@ -44,11 +47,18 @@ export const ControlContainer = ({ onSynthesize }) => {

// Default to initial voice once all voices are loaded.
useEffect(() => {
if (voices[0]) {
setSelectedVoice(mapVoicesToDropdownItems(voices)[0]);
if (voices[1]) {
onSelectVoice(mapVoicesToDropdownItems(voices)[1]);
}
}, [voices]);

const onSelectVoice = voice => {
setSelectedVoice(voice);

const text = sampleText[voice.id];
setText(text);
};

return (
<Tile className="control-container">
<h3 className="container-title">Input</h3>
Expand All @@ -60,7 +70,7 @@ export const ControlContainer = ({ onSynthesize }) => {
id="voice-model-dropdown"
label="Select a voice model"
onChange={newModel => {
setSelectedVoice(newModel.selectedItem);
onSelectVoice(newModel.selectedItem);
}}
items={mapVoicesToDropdownItems(voices)}
selectedItem={selectedVoice && selectedVoice.label}
Expand Down
21 changes: 11 additions & 10 deletions src/components/ServiceContainer/ServiceContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ export const ServiceContainer = () => {
setError(createError(TOKEN_ERROR_TITLE, authJson));
}

try {
synthesize({
accessToken: authJson.accessToken,
element: audioElementRef.current,
text,
voice: voice.id,
});
} catch (error) {
setError(createError(SYNTHESIZE_ERROR_TITLE, error));
}
const audio = await synthesize({
accessToken: authJson.accessToken,
autoPlay: false,
element: audioElementRef.current,
text,
voice: voice.id,
});
audio.play().catch(error => {
console.log('ERROR', error);
setError(createError(SYNTHESIZE_ERROR_TITLE, error.message));
});
};

return (
Expand Down
92 changes: 92 additions & 0 deletions src/data/sampleText.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a636d45

Please sign in to comment.