提交django

wc
翁程 4 years ago
parent c9a7792be9
commit 06c7133257

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="E722" />
</list>
</option>
</inspection_tool>
</profile>
</component>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (base)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/voiceproject.iml" filepath="$PROJECT_DIR$/.idea/voiceproject.iml" />
</modules>
</component>
</project>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="pytest" />
</component>
</module>

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'voiceproject.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>train</title>
</head>
<body>
<form method="post">
{% csrf_token %}
<label for="username">用户名:</label>
<input type="text" id="username" name="username" autofocus required />
<br/>
<input type="submit" value="开始训练"/>
</form>
</body>
</html>

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>upload</title>
</head>
<body>
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
<label for="username">用户名:</label>
<input type="text" id="username" name="username" autofocus required />
<br/>
<input type="file" name="file" />
<br/><br/>
<input type="submit" value="提交音频"/>
<br/><br/>
<a href="{% url 'train' %}">
<button type="button" class="btn btn-primary btn-flat btn-addon m-b-10 m-l-5">
<i class="ti-plus"></i>训练页面
</button>
</a>
</form>
</body>
</html>
<!--在有文件上传的form表单中method属性必须为post而且必须指定它的enctype为"multipart/form-data",表明不对字符进行编码-->

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,5 @@
from django.apps import AppConfig
class VoiceAppConfig(AppConfig):
name = 'voice_app'

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,73 @@
import os
from django.http import HttpResponse
from django.shortcuts import render, redirect
# Create your views here.
def upload(request):
if request.method == "POST": # 请求方法为POST时进行处理
username = request.POST.get('username')
myFile = request.FILES.get("file", None) # 获取上传的文件如果没有文件则默认为None
if not myFile:
return HttpResponse("no files for upload!")
print(username)
print(myFile.name)
traindir = "C:\\Users\\Lenovo\\Desktop\\voiceprint\\dataset\\audio" + "\\" + username
predictdir = "C:\\Users\\Lenovo\\Desktop\\voiceprint\\dataset\\predict" + "\\" + username
isExists = os.path.exists(traindir)
if not isExists:
os.makedirs(traindir)
print(traindir + ' 创建成功')
else:
print(traindir + ' 已存在')
isExists = os.path.exists(predictdir)
if not isExists:
os.makedirs(predictdir)
print(predictdir + ' 创建成功')
else:
print(predictdir + ' 已存在')
files = os.listdir(predictdir)
length = len(files)
myFilename = username + "-" + str(length + 1) + ".wav"
print(myFilename)
destination = open(os.path.join(traindir, myFile.name), 'wb+') # 打开特定的文件进行二进制的写操作
for chunk in myFile.chunks(): # 分块写入训练集文件
destination.write(chunk)
destination.close()
command = "D:\\ffmpeg-4.4-full_build\\bin\\ffmpeg -i " + traindir + "\\" + myFile.name + " -acodec pcm_s16le -ac 2 -ar 44100 " + traindir + "\\" +myFilename
print(command)
os.system(command)
os.remove(traindir + "\\" + myFile.name)
destination2 = open(os.path.join(predictdir, myFile.name), 'wb+') # 打开特定的文件进行二进制的写操作
for chunk in myFile.chunks(): # 分块写入预测集文件
destination2.write(chunk)
destination2.close()
command = "D:\\ffmpeg-4.4-full_build\\bin\\ffmpeg -i " + predictdir + "\\" + myFile.name + " -acodec pcm_s16le -ac 2 -ar 44100 " + predictdir + "\\" + myFilename
print(command)
os.system(command)
os.remove(predictdir + "\\" + myFile.name)
return redirect('upload')
else:
return render(request, 'upload.html')
def train(request):
if request.method == "POST": # 请求方法为POST时进行处理
username = request.POST.get('username')
command = "python C:\\Users\\Lenovo\\Desktop\\voiceprint\\create_data.py" + " " + username
os.system(command)
return HttpResponse("正在训练!")
else:
return render(request, 'train.html')

@ -0,0 +1,16 @@
"""
ASGI config for voiceproject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'voiceproject.settings')
application = get_asgi_application()

@ -0,0 +1,121 @@
"""
Django settings for voiceproject project.
Generated by 'django-admin startproject' using Django 3.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'njo00q@!#%s+m=lh&vh7i1&fhr8t3ck4nf=1nh*r)z$+#)t@_i'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['192.168.8.127', 'localhost', '0.0.0.0:8000', '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'voice_app',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'voiceproject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'voiceproject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'

@ -0,0 +1,24 @@
"""voiceproject URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from voice_app import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.upload, name='upload'),
path('train/', views.train, name='train'),
]

@ -0,0 +1,16 @@
"""
WSGI config for voiceproject project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'voiceproject.settings')
application = get_wsgi_application()
Loading…
Cancel
Save