diff --git a/src/Robot/voiceproject/.idea/.gitignore b/src/Robot/voiceproject/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/src/Robot/voiceproject/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/Robot/voiceproject/.idea/inspectionProfiles/Project_Default.xml b/src/Robot/voiceproject/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..75a9f69 --- /dev/null +++ b/src/Robot/voiceproject/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/src/Robot/voiceproject/.idea/inspectionProfiles/profiles_settings.xml b/src/Robot/voiceproject/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/src/Robot/voiceproject/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/src/Robot/voiceproject/.idea/misc.xml b/src/Robot/voiceproject/.idea/misc.xml new file mode 100644 index 0000000..4530676 --- /dev/null +++ b/src/Robot/voiceproject/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/src/Robot/voiceproject/.idea/modules.xml b/src/Robot/voiceproject/.idea/modules.xml new file mode 100644 index 0000000..ff40c75 --- /dev/null +++ b/src/Robot/voiceproject/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Robot/voiceproject/.idea/voiceproject.iml b/src/Robot/voiceproject/.idea/voiceproject.iml new file mode 100644 index 0000000..4f2c9af --- /dev/null +++ b/src/Robot/voiceproject/.idea/voiceproject.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Robot/voiceproject/db.sqlite3 b/src/Robot/voiceproject/db.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/src/Robot/voiceproject/manage.py b/src/Robot/voiceproject/manage.py new file mode 100644 index 0000000..1f05043 --- /dev/null +++ b/src/Robot/voiceproject/manage.py @@ -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() diff --git a/src/Robot/voiceproject/templates/train.html b/src/Robot/voiceproject/templates/train.html new file mode 100644 index 0000000..efc5cae --- /dev/null +++ b/src/Robot/voiceproject/templates/train.html @@ -0,0 +1,17 @@ + + + + + train + + +
+ {% csrf_token %} + + +
+ + +
+ + \ No newline at end of file diff --git a/src/Robot/voiceproject/templates/upload.html b/src/Robot/voiceproject/templates/upload.html new file mode 100644 index 0000000..280fe05 --- /dev/null +++ b/src/Robot/voiceproject/templates/upload.html @@ -0,0 +1,26 @@ + + + + + upload + + +
+ {% csrf_token %} + + +
+ +

+ +

+ + + +
+ + + + \ No newline at end of file diff --git a/src/Robot/voiceproject/voice_app/__init__.py b/src/Robot/voiceproject/voice_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/Robot/voiceproject/voice_app/__pycache__/__init__.cpython-37.pyc b/src/Robot/voiceproject/voice_app/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..8b889a8 Binary files /dev/null and b/src/Robot/voiceproject/voice_app/__pycache__/__init__.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voice_app/__pycache__/admin.cpython-37.pyc b/src/Robot/voiceproject/voice_app/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..d3f947c Binary files /dev/null and b/src/Robot/voiceproject/voice_app/__pycache__/admin.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voice_app/__pycache__/models.cpython-37.pyc b/src/Robot/voiceproject/voice_app/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..e98f0b1 Binary files /dev/null and b/src/Robot/voiceproject/voice_app/__pycache__/models.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voice_app/__pycache__/views.cpython-37.pyc b/src/Robot/voiceproject/voice_app/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..aa38721 Binary files /dev/null and b/src/Robot/voiceproject/voice_app/__pycache__/views.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voice_app/admin.py b/src/Robot/voiceproject/voice_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/Robot/voiceproject/voice_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/Robot/voiceproject/voice_app/apps.py b/src/Robot/voiceproject/voice_app/apps.py new file mode 100644 index 0000000..0fac99b --- /dev/null +++ b/src/Robot/voiceproject/voice_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class VoiceAppConfig(AppConfig): + name = 'voice_app' diff --git a/src/Robot/voiceproject/voice_app/migrations/__init__.py b/src/Robot/voiceproject/voice_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/Robot/voiceproject/voice_app/migrations/__pycache__/__init__.cpython-37.pyc b/src/Robot/voiceproject/voice_app/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..c3ff0b4 Binary files /dev/null and b/src/Robot/voiceproject/voice_app/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voice_app/models.py b/src/Robot/voiceproject/voice_app/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/src/Robot/voiceproject/voice_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/src/Robot/voiceproject/voice_app/tests.py b/src/Robot/voiceproject/voice_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/Robot/voiceproject/voice_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/Robot/voiceproject/voice_app/views.py b/src/Robot/voiceproject/voice_app/views.py new file mode 100644 index 0000000..a5b0547 --- /dev/null +++ b/src/Robot/voiceproject/voice_app/views.py @@ -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') diff --git a/src/Robot/voiceproject/voiceproject/__init__.py b/src/Robot/voiceproject/voiceproject/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/Robot/voiceproject/voiceproject/__pycache__/__init__.cpython-37.pyc b/src/Robot/voiceproject/voiceproject/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..1eafbb5 Binary files /dev/null and b/src/Robot/voiceproject/voiceproject/__pycache__/__init__.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voiceproject/__pycache__/settings.cpython-37.pyc b/src/Robot/voiceproject/voiceproject/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000..2302f2b Binary files /dev/null and b/src/Robot/voiceproject/voiceproject/__pycache__/settings.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voiceproject/__pycache__/urls.cpython-37.pyc b/src/Robot/voiceproject/voiceproject/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..460f59c Binary files /dev/null and b/src/Robot/voiceproject/voiceproject/__pycache__/urls.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voiceproject/__pycache__/wsgi.cpython-37.pyc b/src/Robot/voiceproject/voiceproject/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 0000000..c12246c Binary files /dev/null and b/src/Robot/voiceproject/voiceproject/__pycache__/wsgi.cpython-37.pyc differ diff --git a/src/Robot/voiceproject/voiceproject/asgi.py b/src/Robot/voiceproject/voiceproject/asgi.py new file mode 100644 index 0000000..050c256 --- /dev/null +++ b/src/Robot/voiceproject/voiceproject/asgi.py @@ -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() diff --git a/src/Robot/voiceproject/voiceproject/settings.py b/src/Robot/voiceproject/voiceproject/settings.py new file mode 100644 index 0000000..5960715 --- /dev/null +++ b/src/Robot/voiceproject/voiceproject/settings.py @@ -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/' diff --git a/src/Robot/voiceproject/voiceproject/urls.py b/src/Robot/voiceproject/voiceproject/urls.py new file mode 100644 index 0000000..5ab027f --- /dev/null +++ b/src/Robot/voiceproject/voiceproject/urls.py @@ -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'), +] diff --git a/src/Robot/voiceproject/voiceproject/wsgi.py b/src/Robot/voiceproject/voiceproject/wsgi.py new file mode 100644 index 0000000..89f7b54 --- /dev/null +++ b/src/Robot/voiceproject/voiceproject/wsgi.py @@ -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()