Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
aidepyaudio
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Snell committed Nov 13, 2018
1 parent c3f94e0 commit c1b27da
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 75 deletions.
23 changes: 22 additions & 1 deletion Serveur/ApiExamAI/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
from django.contrib import admin
from .models import Surveillance, Eleve
from django.utils.text import Truncator

# Register your models here.

class EleveAdmin(admin.ModelAdmin):
list_display = ('idul', 'dateCo', 'apercu_clee')
list_filter = ('idul', 'dateCo',)
date_hierarchy = 'dateCo'
ordering = ('dateCo', )
search_fields = ('idul', 'dateCo')

def apercu_clee(self, eleve):
"""
Retourne les 40 premiers caractères du contenu de l'article,
suivi de points de suspension si le texte est plus long.
"""
return Truncator(eleve.clee).chars(40, truncate='...')

# En-tête de notre colonne
apercu_clee.short_description = 'Aperçu de la clée publique'


admin.site.register(Eleve, EleveAdmin)
31 changes: 31 additions & 0 deletions Serveur/ApiExamAI/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 2.1.2 on 2018-11-10 23:25

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Eleve',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('idul', models.CharField(max_length=7)),
('clee', models.IntegerField()),
('secretPartage', models.IntegerField()),
('dateCo', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Date de connection')),
('suspect', models.IntegerField()),
('photo', models.ImageField(upload_to='')),
],
options={
'verbose_name': 'eleve',
'ordering': ['idul'],
},
),
]
48 changes: 48 additions & 0 deletions Serveur/ApiExamAI/migrations/0002_auto_20181111_1420.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 2.1.2 on 2018-11-11 19:20

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('ApiExamAI', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Surveillance',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('suspect', models.IntegerField(default=0)),
('photo', models.ImageField(default=None, upload_to='')),
],
options={
'verbose_name': 'eleve',
'ordering': ['suspect'],
},
),
migrations.RemoveField(
model_name='eleve',
name='photo',
),
migrations.RemoveField(
model_name='eleve',
name='secretPartage',
),
migrations.RemoveField(
model_name='eleve',
name='suspect',
),
migrations.AlterField(
model_name='eleve',
name='dateCo',
field=models.DateTimeField(auto_now_add=True, verbose_name='Date de connection'),
),
migrations.AddField(
model_name='eleve',
name='surveille',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, to='ApiExamAI.Surveillance'),
),
]
17 changes: 17 additions & 0 deletions Serveur/ApiExamAI/migrations/0003_remove_eleve_surveille.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.1.2 on 2018-11-12 01:43

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ApiExamAI', '0002_auto_20181111_1420'),
]

operations = [
migrations.RemoveField(
model_name='eleve',
name='surveille',
),
]
38 changes: 37 additions & 1 deletion Serveur/ApiExamAI/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
from django.db import models
from django.utils import timezone

# Create your models here.

class Surveillance(models.Model):
suspect = models.IntegerField(default=0)
photo = models.ImageField(upload_to="photos/", default=None)

class Meta:
verbose_name = "surveillance"
ordering = ['suspect']

def __str__(self):
return self.suspect


class Eleve(models.Model):
idul = models.CharField(max_length=7)
clee = models.IntegerField()
dateCo = models.DateTimeField(auto_now_add=True,
verbose_name="Date de connection")
# default=timezone.now,
#surveille = models.OneToOneField(Surveillance, on_delete=models.PROTECT, null=True)
# PROTECT ou CASCADE ou SET_NULL

class Meta:
verbose_name = "eleve"
ordering = ['idul']

def __str__(self):
return self.idul


"""
>> > article = Article(titre="Bonjour", auteur="Maxime")
>> > for article in Article.objects.filter(auteur="Maxime"):
>> > Article.objects.filter(titre__contains="crêpe")
>> > Article.objects.filter(date__lt=timezone.now())
"""
5 changes: 5 additions & 0 deletions Serveur/ApiExamAI/templates/ApiExamAI/Acceuil_eleve.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "base.html"%}
{% block title %} Recherche d'eleve {% endblock title %}
{% block content %}
<h1>Taper dans la barre de recherche pour trouver un eleve</h1>
{% endblock content %}
7 changes: 7 additions & 0 deletions Serveur/ApiExamAI/templates/ApiExamAI/Aide.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html"%}
{% block title %} Page d'aide {% endblock title %}
{% block content %}
<h1>Expliquons comment ca marche</h1>
<p> ici </p>
<p> plop </p>
{% endblock content %}
8 changes: 6 additions & 2 deletions Serveur/ApiExamAI/templates/ApiExamAI/eleve.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{% extends "base.html"%}
<h1>Surveillance en cours</h1>
<p>Le {{date}} élève {{ idul }}</p>
{% block title %} Surveillance de {{idul}} en cours {% endblock title %}
{% block content %}
<h1>Surveillance en cours</h1>
<p>Le {{date}} élève {{ idul }}</p>
<p> plop </p>
{% endblock content %}
3 changes: 3 additions & 0 deletions Serveur/ApiExamAI/templates/ApiExamAI/stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends 'base.html' %}
{% block title %} Statistiques {% endblock title %}
{% block content %} Les stats sont affichées ici{% endblock content %}
13 changes: 8 additions & 5 deletions Serveur/ApiExamAI/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
from . import views

urlpatterns = [
path('accueil', views.home),
path('eleve/<str:idul>', views.view_eleve),
path('articles/<int:year>/<int:month>', views.list_articles),
re_path(r'(?P<idul>^[A-Z]{5}\d{0,2}$)', views.view_eleve, name='eleve')
]
path('accueil', views.home, name='Acceuil'),
path('Acceuil_eleve', views.Acceuil_eleve, name="Acceuil_eleve"),
path('statistiques', views.stats, name='stats'),
path('connection-<str:idul>', views.connection, name='connection'),
path('Aide', views.Aide, name="Aide"),
re_path(r'^eleve/(?P<idul>[A-Z]{5}\d{0,2}$)',
views.view_eleve, name='eleve')
]
43 changes: 27 additions & 16 deletions Serveur/ApiExamAI/views.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.http import Http404
from django.shortcuts import redirect
from django.http import HttpResponse, Http404
from django.shortcuts import render, redirect, get_object_or_404
from datetime import datetime
from Crypto.PublicKey import RSA
from . import models


def list_articles(request, year, month):
if month > 12:
#return redirect(view_eleve, idul='PISNE')
return redirect('eleve', idul='PISNE')
#return redirect("https://www.djangoproject.com")
else :
return HttpResponse(
"Vous avez demandé {0} et {1} !".format(year,month))

def home(request):
return HttpResponse("""
<h1>Bienvenue ExamAi !</h1>
<p>Api : getInfos ou plop </p>
""")

def view_eleve(request, idul):
#return HttpResponse("Vous avez demandé l'eleve {0} !".format(idul))

def Acceuil_eleve(request):
return render(request, 'ApiExamAI/Acceuil_eleve.html')


def view_eleve(request, idul="AAAAA"):
# return HttpResponse("Vous avez demandé l'eleve {0} !".format(idul))
date = datetime.now()
#eturn render(request, 'ApiExamAI/eleve.html', date)
# return render(request, 'ApiExamAI/eleve.html', date)
return render(request, 'ApiExamAI/eleve.html', locals())


def stats(request):
return render(request, 'ApiExamAI/stats.html')


def Aide(request):
return render(request, 'ApiExamAI/Aide.html')


def connection(request, idul):
eleve = models.Eleve(idul=idul)
eleve.clee = RSA.generate(4096).publickey()
#eleve.surveille.suspect = 0
# public_key.encrypt(TrucQuonVeutSecuriser)
9 changes: 6 additions & 3 deletions Serveur/Serveur/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

Expand Down Expand Up @@ -56,8 +56,8 @@
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -121,3 +121,6 @@
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load static %}
<!DOCTYPE html>
<html lang="fr">
<head>
Expand All @@ -9,9 +10,9 @@
<nav>
{% block nav %}
<ul>
<li><a href="/">Statistiques</a></li>
<li><a href="/blog/">Élève</a></li>
<li><a href="/contact/">Fonctionnement</a></li>
<li><a href="{% url "stats" %}">Statistiques</a></li>
<li><a href="{% url "Acceuil_eleve" %}">Élève</a></li>
<li><a href="{% url "Aide" %}">Aide</a></li>
</ul>
{% endblock %}
</nav>
Expand All @@ -20,4 +21,4 @@
</section>
<footer>&copy; ExamAi, Maitrise, Pierre Snell</footer>
</body>
</html>
</html>
45 changes: 22 additions & 23 deletions detectSound/plop.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
from pygame import mixer
import speech_recognition as sr
from gtts import gTTS
#quiet the endless 'insecurerequest' warning
# quiet the endless 'insecurerequest' warning
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

from pygame import mixer
mixer.init()

while (True == True):
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
#print("Please wait. Calibrating microphone...")
# listen for 1 second and create the ambient noise energy level
r.adjust_for_ambient_noise(source, duration=1)
print("Say something!")
audio = r.listen(source,phrase_time_limit=5)
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
#print("Please wait. Calibrating microphone...")
# listen for 1 second and create the ambient noise energy level
r.adjust_for_ambient_noise(source, duration=1)
print("Say something!")
audio = r.listen(source, phrase_time_limit=5)

# recognize speech using Sphinx/Google
try:
#response = r.recognize_sphinx(audio)
response = r.recognize_google(audio)
print("I think you said '" + response + "'")
tts = gTTS(text="I think you said "+str(response), lang='en')
tts.save("response.mp3")
mixer.music.load('response.mp3')
mixer.music.play()

try:
#response = r.recognize_sphinx(audio)
response = r.recognize_google(audio)
print("I think you said '" + response + "'")
tts = gTTS(text="I think you said "+str(response), lang='en')
tts.save("response.mp3")
mixer.music.load('response.mp3')
mixer.music.play()

except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
Loading

0 comments on commit c1b27da

Please sign in to comment.