Commit 73bcf427 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

ajout fonction pause dans synthèse vocale

parent ad48212b
......@@ -4,6 +4,10 @@ import os
from contextlib import closing
# Source : http://ipa-reader.xyz/
# Liste des phonèmes acceptés pour le français : https://docs.aws.amazon.com/polly/latest/dg/ph-table-french.html
# Liste des tags ssml disponibles : https://docs.aws.amazon.com/polly/latest/dg/supportedtags.html#s-tag
def lambda_handler(ipa, loc):
# init polly
polly = boto3.client("polly")
......@@ -17,8 +21,10 @@ def lambda_handler(ipa, loc):
text = text.replace("/", "")
# generate phoneme tag for polly to read
phoneme = f"<prosody rate='85%'><phoneme alphabet='ipa' ph='{text}'></phoneme></prosody>" #<prosody rate='85%'></prosody>
text = text.replace(' ', "'></phoneme><break/><phoneme alphabet='ipa' ph='")
phoneme = "<prosody rate='85%'><phoneme alphabet='ipa' ph='"+text+"'></phoneme></prosody>" #<prosody rate='85%'></prosody>
print(phoneme)
# send to polly, requesting mp3 back
response = polly.synthesize_speech(
OutputFormat="mp3",
......
......@@ -213,6 +213,7 @@ function writeEnter(){ // <span id="g0" onclick="putAnchor(this.id)">&nbsp;</spa
var graphSpan = document.createElement("span");
graphSpan.setAttribute("id", "g"+Math.random().toString(36).substring(2,9));
graphSpan.setAttribute('onclick', "putAnchor(this.id)");
graphSpan.setAttribute('class', "text pause");
graphSpan.innerHTML = '&nbsp;';
insertAfter(document.getElementById(curseurPos), graphSpan);
......@@ -581,17 +582,24 @@ function openInNewTab() {
var currentIpa = "";
async function playIpa() {
if (thisPageLang == 'fr'){
// Si quelque chose est écrit...
if (document.getElementsByClassName('text').length > 0) {
// PRÉPARATION COLIS
// on récupère tous les élément classe "text" et on récupère leur classe phon_*
var phonEllist = document.getElementsByClassName('text');
var ipa = "";
for (e=0; e<phonEllist.length; e++){
var phon = phonEllist[e].classList[1];
if (phon.match(/phon_.*/)) {
ipa += phon2api[phon];
// on parse les classe c de l'élement e
for (c=0; c<phonEllist[e].classList.length; c++){
// si la classe match "phon_.*"" alors on récupère l'équivalent api
if (phonEllist[e].classList[c].match(/phon_.*/)){
ipa += phon2api[phonEllist[e].classList[c]];
} else if (phonEllist[e].classList[c].match(/pause/)) {
// si la classe match "pause" on insert une espace (qui sera convertie en <break> dans text2speech.py)
ipa += ' ';
}
}
}
ipa = ipa.trim(); // suppression des espaces en début ou en fin
if (ipa != currentIpa){
console.log("lecture de ", ipa);
currentIpa = ipa;
......
......@@ -79,6 +79,11 @@
border: 2px solid #5cb85c;
}
.boutons button {
border: solid 1px black;
padding: auto 15px;
}
.textZone {
display: inline-table;
......
......@@ -43,16 +43,16 @@
<div id="audio"></div>
<div class="boutons">
<button type="button" class="btn btn-secondary" onclick="writeGraph('. ','punct')">.</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(', ','punct')">,</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' ? ','punct')">?</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' ! ','punct')">!</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph('. ','punct pause')">.</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(', ','punct pause')">,</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' ? ','punct pause')">?</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' ! ','punct pause')">!</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' : ','punct')">:</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' ; ','punct')">;</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' ; ','punct pause')">;</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph('-','punct')">-</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' « ','punct')">«</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' » ','punct')">»</button>
<button type="button" class="btn btn-secondary" onclick="writeGraph(' ','punct')" class="btn-car-space"><span id="sp_btnspace" class="langspan"></span></button>
<button type="button" class="btn btn-warning btn-lg px-5" onclick="writeGraph(' ','punct')" class="btn-car-space"><span id="sp_btnspace" class="langspan"></span></button>
<button type="button" class="btn btn-secondary" onclick="writeEnter()" class="btn-car-enter" title="Aller à la ligne"></button>
<button type="button" class="btn btn-secondary" onclick="erasePreviousSpan()"><span id="sp_btnerase" class="langspan"></span></button>
<button type="button" class="btn btn-secondary" onclick="gotoPrecedent()" title="Aller à la graphie précédente"><svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-caret-left-fill nobg" viewBox="0 0 16 16"><path d="M3.86 8.753l5.482 4.796c.646.566 1.658.106 1.658-.753V3.204a1 1 0 0 0-1.659-.753l-5.48 4.796a1 1 0 0 0 0 1.506z"/></svg></button>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment