-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from HoseaCodes/main
Main
- Loading branch information
Showing
17 changed files
with
2,472 additions
and
3,117 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { DisplayItem } from '../../Layout/Text/styledText'; | ||
import { AiFillPlayCircle, AiFillPauseCircle, AiFillStop } from 'react-icons/ai'; | ||
|
||
const TextToSpeech = ({ text }) => { | ||
const [isPaused, setIsPaused] = useState(false); | ||
const [utterance, setUtterance] = useState(null); | ||
|
||
useEffect(() => { | ||
const synth = window.speechSynthesis; | ||
const u = new SpeechSynthesisUtterance(text); | ||
|
||
setUtterance(u); | ||
setIsPaused(true) | ||
|
||
return () => { | ||
synth.cancel(); | ||
}; | ||
}, [text]); | ||
|
||
const handlePlay = () => { | ||
const synth = window.speechSynthesis; | ||
const voices = synth.getVoices(); | ||
|
||
utterance.voice = voices[15]; | ||
utterance.rate = 0.95; | ||
|
||
if (isPaused) { | ||
synth.resume(); | ||
} | ||
|
||
synth.speak(utterance); | ||
|
||
setIsPaused(false); | ||
}; | ||
|
||
const handlePause = () => { | ||
const synth = window.speechSynthesis; | ||
|
||
synth.pause(); | ||
|
||
setIsPaused(true); | ||
}; | ||
|
||
const handleStop = () => { | ||
const synth = window.speechSynthesis; | ||
|
||
synth.cancel(); | ||
|
||
setIsPaused(true); | ||
}; | ||
|
||
return ( | ||
<div style={{display: 'flex'}}> | ||
{ | ||
isPaused ? | ||
<DisplayItem Green onClick={handlePlay}> | ||
<AiFillPlayCircle style={{fontSize: 'larger'}}/> | ||
{isPaused ? "Listen" : "Resume"} | ||
</DisplayItem> | ||
: | ||
<DisplayItem Green onClick={handlePause}> | ||
<AiFillPauseCircle style={{fontSize: 'larger'}}/> | ||
Pause | ||
</DisplayItem> | ||
|
||
} | ||
| ||
<DisplayItem Red onClick={handleStop}> | ||
<AiFillStop style={{fontSize: 'larger'}}/> | ||
Stop | ||
</DisplayItem> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TextToSpeech; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { Component } from 'react'; | ||
import Container from 'react-bootstrap/Container'; | ||
import Form from 'react-bootstrap/Form'; | ||
|
||
class SimpleForm extends Component { | ||
render() { | ||
return ( | ||
<Container> | ||
<Form> | ||
<Form.Group controlId="form.Name"> | ||
<Form.Label>Name</Form.Label> | ||
<Form.Control type="text" placeholder="Enter name" /> | ||
</Form.Group> | ||
<Form.Group controlId="form.Email"> | ||
<Form.Label>Email address</Form.Label> | ||
<Form.Control type="email" placeholder="[email protected]" /> | ||
</Form.Group> | ||
<Form.Group controlId="form.Textarea"> | ||
<Form.Label>Comment</Form.Label> | ||
<Form.Control as="textarea" rows={3} /> | ||
</Form.Group> | ||
</Form> | ||
</Container> | ||
); | ||
} | ||
|
||
} | ||
|
||
export default SimpleForm |
Oops, something went wrong.