Commit 3af734de authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

ajout class trace synthese vocale

parent 73bcf427
......@@ -23,7 +23,7 @@ def lambda_handler(ipa, loc):
# generate phoneme tag for polly to read
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(
......@@ -40,4 +40,4 @@ def lambda_handler(ipa, loc):
with closing(response["AudioStream"]) as stream:
audio = base64.encodebytes(stream.read())
return audio.decode("ascii")
\ No newline at end of file
return (audio.decode("ascii"),len(phoneme))
\ No newline at end of file
from django.shortcuts import render, HttpResponseRedirect
from django.http import JsonResponse
from .models import Serie
from django.forms.models import model_to_dict
from django.views.generic import ListView, DetailView
import subprocess, json, os, tempfile
from django.forms.models import model_to_dict
from .models import Serie
from .text2speech import lambda_handler
from users.views import saveTraceSynthVoc
from user_agents import parse
import subprocess, json, os, tempfile
### Chargement de la base de données
dbFile = '../db/db_phonographe.json'
......@@ -123,12 +128,24 @@ def openPlayerPhono(request, pk):
print("Demande ouverture série", serieContent.nom, ' (', pk, ')')
return render(request, 'playerPhono.html', {'updateTime': updateTimeStr, 'serieContent':serieContent})
def playIpa(request):
colis = json.loads(request.body)
ipa = colis['ipa']
print("Lecture de ["+ipa+"]")
audioBytes, lenssml = lambda_handler(ipa,"Celine")
data = {
"audio": lambda_handler(ipa,"Celine")
"audio": audioBytes
}
saveTraceSynthVoc({
"user" : request.user,
"userAgent" : parse(request.META['HTTP_USER_AGENT']),
"userIp" : get_client_ip(request),
"appli" : colis['appli'],
"lenssml" : lenssml
})
return JsonResponse(data)
\ No newline at end of file
......@@ -599,13 +599,16 @@ async function playIpa() {
}
}
}
ipa = ipa.trim(); // suppression des espaces en début ou en fin
if (ipa != currentIpa){
console.log("lecture de ", ipa);
currentIpa = ipa;
// ON EMBALLE TOUT ÇA
var colis = {
'ipa': ipa
'ipa': ipa,
'appli': 'phonographe'
};
......
# Generated by Django 3.0.5 on 2021-02-24 14:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0005_trace'),
]
operations = [
migrations.CreateModel(
name='SynthVocTrace',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user', models.CharField(default='Anonymous', max_length=50)),
('userAgent', models.CharField(default='Anonymous', max_length=200)),
('userIp', models.CharField(default='Anonymous', max_length=50)),
('date', models.DateTimeField(auto_now_add=True)),
('appli', models.TextField()),
('lenssml', models.IntegerField()),
],
),
migrations.AddField(
model_name='trace',
name='userAgent',
field=models.CharField(default='Anonymous', max_length=200),
),
migrations.AddField(
model_name='trace',
name='userIp',
field=models.CharField(default='Anonymous', max_length=50),
),
]
......@@ -21,11 +21,22 @@ class Profile(models.Model):
class Trace(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
userAgent = models.CharField(max_length=200)
userIp = models.CharField(max_length=50)
userAgent = models.CharField(max_length=200, default='Anonymous')
userIp = models.CharField(max_length=50, default='Anonymous')
date = models.DateTimeField(auto_now_add=True, auto_now=False)
appli = models.TextField()
content = models.TextField(default='{}')
def __str__(self):
return f'Trace n°{self.id} \n\tapp: {self.appli} \n\tuser: {self.user.username} \n\tdate: {self.date} \n\tcontent: {self.content} \n\tip: {self.userIp} \n\tagent: {self.userAgent}'
class SynthVocTrace(models.Model):
user = models.CharField(max_length=50, default='Anonymous')
userAgent = models.CharField(max_length=200, default='Anonymous')
userIp = models.CharField(max_length=50, default='Anonymous')
date = models.DateTimeField(auto_now_add=True, auto_now=False)
appli = models.TextField()
lenssml = models.IntegerField()
def __str__(self):
return f'Trace n°{self.id} \n\tapp: {self.appli} \n\tuser: {self.user.username} \n\tdate: {self.date} \n\tip: {self.userIp} \n\tagent: {self.userAgent}'
\ No newline at end of file
......@@ -7,8 +7,7 @@ from django.http import JsonResponse
from .forms import UserRegisterForm, CreateSerieForm, UserUpdateForm, ProfileUpdateForm, CreateMot, UploadAudioForm, UploadImageForm
from clavier.models import Serie, Mot, Audio
from .models import Trace
from clavier.views import get_client_ip
from .models import Trace, SynthVocTrace
from user_agents import parse
from datetime import date
......@@ -170,7 +169,6 @@ def saveTrace(request):
colis = json.loads(request.body)
newTrace = Trace()
newTrace.user = request.user
newTrace.userAgent = parse(request.META['HTTP_USER_AGENT'])
newTrace.userIp = get_client_ip(request)
......@@ -185,3 +183,15 @@ def saveTrace(request):
'saved': True
}
return JsonResponse(data)
def saveTraceSynthVoc(colis):
newTrace = SynthVocTrace()
newTrace.user = colis['user']
newTrace.userAgent = colis['userAgent']
newTrace.userIp = colis['userIp']
newTrace.appli = colis['appli']
newTrace.lenssml = colis['lenssml']
newTrace.save()
print("Trace synthèse vocale enregistrée", colis['lenssml'])
\ No newline at end of file
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