@@ -10,12 +10,15 @@ import {
1010 Tile ,
1111} from 'carbon-components-react' ;
1212import useDataApi from 'use-data-api' ;
13+ import { sampleText } from '../../data/sampleText' ;
1314
1415const VOICES_ENDPOINT = '/api/voices' ;
1516
1617const mapVoicesToDropdownItems = voices =>
1718 voices
18- . sort ( ( voiceA , voiceB ) => voiceA . description > voiceB . description )
19+ . sort ( ( voiceA , voiceB ) =>
20+ voiceA . description . localeCompare ( voiceB . description ) ,
21+ )
1922 . map ( voice => {
2023 const colonIndex = voice . description . indexOf ( ':' ) ;
2124 const voicePersonName = voice . description . substring ( 0 , colonIndex ) ;
@@ -44,11 +47,18 @@ export const ControlContainer = ({ onSynthesize }) => {
4447
4548 // Default to initial voice once all voices are loaded.
4649 useEffect ( ( ) => {
47- if ( voices [ 0 ] ) {
48- setSelectedVoice ( mapVoicesToDropdownItems ( voices ) [ 0 ] ) ;
50+ if ( voices [ 1 ] ) {
51+ onSelectVoice ( mapVoicesToDropdownItems ( voices ) [ 1 ] ) ;
4952 }
5053 } , [ voices ] ) ;
5154
55+ const onSelectVoice = voice => {
56+ setSelectedVoice ( voice ) ;
57+
58+ const text = sampleText [ voice . id ] ;
59+ setText ( text ) ;
60+ } ;
61+
5262 return (
5363 < Tile className = "control-container" >
5464 < h3 className = "container-title" > Input</ h3 >
@@ -60,7 +70,7 @@ export const ControlContainer = ({ onSynthesize }) => {
6070 id = "voice-model-dropdown"
6171 label = "Select a voice model"
6272 onChange = { newModel => {
63- setSelectedVoice ( newModel . selectedItem ) ;
73+ onSelectVoice ( newModel . selectedItem ) ;
6474 } }
6575 items = { mapVoicesToDropdownItems ( voices ) }
6676 selectedItem = { selectedVoice && selectedVoice . label }
0 commit comments