From d16eb297bcd280107142e72fa283dbcf0bdc4512 Mon Sep 17 00:00:00 2001
From: yunyin <2977138976@qq.com>
Date: Thu, 30 May 2024 16:29:11 +0800
Subject: [PATCH] 0530
---
0530/scripts.js | 29 ++++++++++++++++++++++++
0530/登录.html | 24 ++++++++++++++++++++
0530/转语音.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 109 insertions(+)
create mode 100644 0530/scripts.js
create mode 100644 0530/登录.html
create mode 100644 0530/转语音.py
diff --git a/0530/scripts.js b/0530/scripts.js
new file mode 100644
index 0000000..5542a97
--- /dev/null
+++ b/0530/scripts.js
@@ -0,0 +1,29 @@
+document.getElementById('loginForm').addEventListener('submit', async (event) => {
+ event.preventDefault(); // 阻止表单默认提交行为
+
+ const username = document.getElementById('username').value;
+ const password = document.getElementById('password').value;
+
+ try {
+ // 调用API进行登录验证
+ const response = await fetch('/api/login', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({ username, password })
+ });
+
+ if (response.ok) {
+ // 登录成功,跳转到功能页面
+ window.location.href = '';
+ } else {
+ // 显示错误信息
+ alert('登录失败');
+ }
+ } catch (error) {
+ // 处理网络错误
+ console.error('Error:', error);
+ alert('无法连接到服务器,请检查网络');
+ }
+});
diff --git a/0530/登录.html b/0530/登录.html
new file mode 100644
index 0000000..59bfdd5
--- /dev/null
+++ b/0530/登录.html
@@ -0,0 +1,24 @@
+
+
+
+
+
+ 语音登录
+
+
+
+
+
Login
+
+
+
+
+
diff --git a/0530/转语音.py b/0530/转语音.py
new file mode 100644
index 0000000..4fd7b45
--- /dev/null
+++ b/0530/转语音.py
@@ -0,0 +1,56 @@
+import tkinter as tk
+from tkinter import ttk
+import pyttsx3
+import speech_recognition as sr
+from flask import Flask, request, jsonify
+
+app = Flask(__name__)
+
+@app.route('/api/login', methods=['POST'])
+def login():
+ username = request.json.get('username')
+ password = request.json.get('password')
+
+ # 这里应该替换为实际的用户验证逻辑,比如查询数据库
+ if username == 'abc' and password == '123':
+ return jsonify({"success": True, "message": "登录成功"})
+ else:
+ return jsonify({"success": False, "message": "用户名或密码错误"}), 401
+
+def text_to_speech():
+ engine = pyttsx3.init()
+ text = text_entry.get("1.0", "end-1c") # 获取文本框中的文本
+ engine.say(text)
+ engine.runAndWait()
+
+
+def main():
+ global text_entry
+
+ # 创建主窗口
+ app = tk.Tk()
+ app.title("文本转语音")
+
+ speed_slider = ttk.Scale(app, from_=50, to=200, orient=tk.HORIZONTAL)
+ speed_slider.set(120) # 默认语速
+ speed_slider.pack()
+
+ # 创建一个标签,用于提示输入文本
+ label = tk.Label(app, text="请输入文字:")
+ label.pack(pady=10)
+
+ # 创建一个文本框,用于用户输入
+ text_entry = tk.Text(app, height=10)
+ text_entry.pack()
+
+ # 创建一个按钮,点击时调用text_to_speech函数
+ convert_button = tk.Button(app, text="识别", command=text_to_speech)
+ convert_button.pack(pady=10)
+
+ # 运行主循环
+ app.mainloop()
+
+
+if __name__ == "__main__":
+ main()
+ app.run(debug=True)
\ No newline at end of file