Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit d1642078 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

enregistrement des audio synthétisés dans la base de donnée pour éviter resynthétisation

parent 63b637ab
......@@ -7,6 +7,7 @@ from .models import Serie
from .text2speech import lambda_handler
from users.views import saveTraceSynthVoc
from users.models import SynthVocRecord
from user_agents import parse
import subprocess, json, os, tempfile
......@@ -134,26 +135,37 @@ def playIpa(request):
ipa = colis['ipa']
lang = colis['lang']
voix = colis['voix']
# debit = colis['debit']
if lang == "fr":
loc = "Celine" if voix == "f" else "Mathieu"
elif lang == "enbr":
loc = "Amy" if voix == "f" else "Brian"
record = SynthVocRecord.objects.filter(ipa=ipa).filter(lang=lang).filter(voix=voix)
if len(record)>0:
print("Un enregistrement existe déjà dans la base de données. Envoi de cet enregistrement.")
audioBytes = record[0].audio
record[0].cptEcoute += 1
record[0].save()
else:
print("Pas d'enregistrement existant. Demande de synthétisation.")
if lang == "fr":
loc = "Celine" if voix == "f" else "Mathieu"
elif lang == "enbr":
loc = "Amy" if voix == "f" else "Brian"
print("Lecture de ["+ipa+"] débit 80%")
audioBytes, lenssml = lambda_handler(ipa, loc)
print("Lecture de ["+ipa+"] débit 80%")
audioBytes, lenssml = lambda_handler(ipa, loc)
saveTraceSynthVoc({
"user" : request.user,
"userAgent" : parse(request.META['HTTP_USER_AGENT']),
"userIp" : get_client_ip(request),
"appli" : colis['appli'],
"lenssml" : lenssml
})
newRecord = SynthVocRecord(ipa=ipa, lang=lang, voix=voix, cptEcoute=0, audio=audioBytes)
newRecord.save()
data = {
"audio": audioBytes
"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
from django.contrib import admin
from .models import Profile, Trace, SynthVocTrace
from .models import Profile, Trace, SynthVocTrace, SynthVocRecord
# TUTO : https://www.youtube.com/watch?v=g5DTIiFAiSk
......@@ -16,3 +16,4 @@ class TracesSynthVoc(admin.ModelAdmin):
admin.site.register(Profile)
admin.site.register(Trace, TracesAdmin)
admin.site.register(SynthVocTrace, TracesSynthVoc)
admin.site.register(SynthVocRecord)
\ No newline at end of file
# Generated by Django 3.0.5 on 2021-03-24 08:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0006_auto_20210224_1445'),
]
operations = [
migrations.CreateModel(
name='SynthVocRecord',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('voix', models.CharField(max_length=1)),
('lang', models.CharField(max_length=15)),
('ipa', models.CharField(max_length=400)),
('audio', models.TextField()),
('cptEcoute', models.IntegerField()),
],
),
]
......@@ -39,4 +39,14 @@ class SynthVocTrace(models.Model):
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
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}'
class SynthVocRecord(models.Model):
voix = models.CharField(max_length=1)
lang = models.CharField(max_length=15)
ipa = models.CharField(max_length=400)
audio = models.TextField()
cptEcoute = models.IntegerField()
def __str__(self):
return f'VocRecord n°{self.id} \n\t[{self.ipa}] {self.lang} {self.voix}\n\tCompteur d\'écoutes: {self.cptEcoute}'
......@@ -9,7 +9,7 @@ from django.template.loader import render_to_string
from .forms import UserRegisterForm, CreateSerieForm, UserUpdateForm, ProfileUpdateForm, CreateMot, UploadAudioForm, UploadImageForm
from clavier.models import Serie, Mot, Audio
from .models import Trace, SynthVocTrace
from .models import Trace, SynthVocTrace, SynthVocRecord
from user_agents import parse
from datetime import date
......
Markdown is supported
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