This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
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 #194 from g0v/語音合成
語音合成
- Loading branch information
Showing
2 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
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,74 @@ | ||
import React from 'react'; | ||
import Transmit from 'react-transmit'; | ||
import Promise from 'bluebird'; | ||
var superagent = require('superagent-promise')(require('superagent'), Promise); | ||
|
||
import Debug from 'debug'; | ||
|
||
var debug = Debug('itaigi:HapSing'); | ||
|
||
class HapSing extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
id: Math.random().toString(36), | ||
}; | ||
} | ||
|
||
componentWillMount() { | ||
this.props.setQueryParams(this.props); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.params === this.props.params) return; | ||
this.props.setQueryParams(nextProps); | ||
} | ||
|
||
componentDidMount() | ||
{ | ||
setTimeout(this.載入.bind(this), Math.random() * 1000); | ||
} | ||
|
||
componentDidUpdate(prevProps, prevState) | ||
{ | ||
setTimeout(this.載入.bind(this), Math.random() * 1000); | ||
} | ||
|
||
載入() { | ||
document.getElementById(this.state.id).load(); | ||
} | ||
|
||
play() { | ||
document.getElementById(this.state.id).play(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className='HuatIm'> | ||
<audio id ={this.state.id}> | ||
<source type='audio/wav' | ||
src={ | ||
'http://服務.意傳.台灣/語音合成?查詢腔口=閩南語&查詢語句=' + encodeURI(this.props.標漢字音標) } | ||
/> | ||
</audio> | ||
<button onClick={this.play.bind(this)} | ||
className='ui compact icon button'> | ||
<i className='icon play'></i> | ||
</button> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Transmit.createContainer(HapSing, { | ||
queries: { | ||
標漢字音標({ 音標 }) { | ||
return ( | ||
superagent.get('http://服務.意傳.台灣/標漢字音標?查詢腔口=閩南語&查詢語句=' + 音標) | ||
.then(({ body }) => (body.翻譯正規化結果)) | ||
.catch((err) => debug(err)) | ||
); | ||
}, | ||
}, | ||
}); |
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