潜江市网站建设_网站建设公司_全栈开发者_seo优化
2025/12/30 15:04:57 网站建设 项目流程

我将为您创建一个完整的中老年手机使用指南生成器系统。这个系统包含多个模块,支持图文生成和语音播放功能。

项目结构

senior_phone_guide/

├── main.py # 主程序入口

├── guide_generator.py # 指南生成器核心模块

├── voice_player.py # 语音播放模块

├── image_generator.py # 图片生成模块

├── config.py # 配置文件

├── requirements.txt # 依赖包列表

├── README.md # 项目说明

└── knowledge_cards/ # 核心知识点卡片

├── basics.md

├── social.md

├── payment.md

└── safety.md

1. 主程序 (main.py)

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

中老年手机使用指南生成器 - 主程序

功能:根据手机型号和功能需求生成个性化使用指南,支持语音播放

作者:AI Assistant

日期:2024年

"""

import sys

from guide_generator import GuideGenerator

from voice_player import VoicePlayer

from config import SUPPORTED_PHONES, GUIDE_TEMPLATES

class SeniorPhoneGuideApp:

def __init__(self):

self.guide_generator = GuideGenerator()

self.voice_player = VoicePlayer()

def show_welcome(self):

"""显示欢迎界面"""

print("=" * 60)

print("🌟 欢迎使用中老年手机使用指南生成器 🌟")

print("=" * 60)

print("本工具专为老年人设计,帮您轻松掌握智能手机使用!")

print("支持主流手机品牌:华为、小米、OPPO、vivo、苹果等")

print("-" * 60)

def get_user_input(self):

"""获取用户输入"""

print("\n📱 请告诉我您的手机信息:")

# 选择手机品牌

print("\n支持的手机品牌:")

for i, brand in enumerate(SUPPORTED_PHONES.keys(), 1):

print(f"{i}. {brand}")

while True:

try:

choice = int(input("\n请选择您的手机品牌(输入数字):"))

brands = list(SUPPORTED_PHONES.keys())

if 1 <= choice <= len(brands):

selected_brand = brands[choice - 1]

break

else:

print("❌ 请输入有效的数字!")

except ValueError:

print("❌ 请输入数字!")

# 选择具体型号

models = SUPPORTED_PHONES[selected_brand]

print(f"\n{selected_brand} 支持的型号:")

for i, model in enumerate(models, 1):

print(f"{i}. {model}")

while True:

try:

choice = int(input(f"\n请选择您的手机型号(输入数字):"))

if 1 <= choice <= len(models):

selected_model = models[choice - 1]

phone_info = f"{selected_brand} {selected_model}"

break

else:

print("❌ 请输入有效的数字!")

except ValueError:

print("❌ 请输入数字!")

# 选择功能需求

print("\n🔧 请选择您需要学习的功能:")

functions = list(GUIDE_TEMPLATES.keys())

for i, func in enumerate(functions, 1):

print(f"{i}. {func}")

selected_functions = []

while True:

try:

choice = input("\n请选择功能(可多选,用逗号分隔,如:1,2,3):")

choices = [int(x.strip()) for x in choice.split(',')]

for c in choices:

if 1 <= c <= len(functions):

selected_functions.append(functions[c - 1])

else:

print(f"❌ {c} 不是有效选项!")

break

else:

if selected_functions:

break

else:

print("❌ 请至少选择一个功能!")

except ValueError:

print("❌ 请输入正确的格式,如:1,2,3")

return phone_info, selected_functions

def generate_guide(self, phone_info, functions):

"""生成使用指南"""

print(f"\n🔄 正在为您的 {phone_info} 生成使用指南...")

guide_content = self.guide_generator.generate_guide(phone_info, functions)

if guide_content:

print("✅ 指南生成成功!")

return guide_content

else:

print("❌ 指南生成失败,请重试!")

return None

def display_guide(self, guide_content):

"""显示生成的指南"""

print("\n" + "=" * 60)

print("📖 您的使用指南已生成:")

print("=" * 60)

for section in guide_content:

print(f"\n📱 {section['title']}")

print("-" * 40)

print(section['content'])

print()

def ask_voice_playback(self):

"""询问是否需要语音播放"""

while True:

choice = input("🔊 是否需要语音播放指南内容?(y/n):").lower()

if choice in ['y', 'yes', '是']:

return True

elif choice in ['n', 'no', '否']:

return False

else:

print("❌ 请输入 y 或 n")

def run(self):

"""运行主程序"""

try:

self.show_welcome()

phone_info, functions = self.get_user_input()

guide_content = self.generate_guide(phone_info, functions)

if guide_content:

self.display_guide(guide_content)

if self.ask_voice_playback():

print("\n🔊 开始语音播放...")

self.voice_player.play_guide(guide_content)

print("\n💡 小贴士:")

print("- 建议将指南保存到手机相册,方便随时查看")

print("- 可以先从最基础的功能开始练习")

print("- 遇到问题时可以重新生成特定功能的指南")

except KeyboardInterrupt:

print("\n\n👋 感谢使用,再见!")

except Exception as e:

print(f"\n❌ 发生错误:{e}")

print("请检查输入是否正确,或联系技术支持")

if __name__ == "__main__":

app = SeniorPhoneGuideApp()

app.run()

2. 指南生成器 (guide_generator.py)

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

指南生成器模块

负责根据用户需求生成个性化的手机使用指南

"""

import json

from datetime import datetime

from image_generator import ImageGenerator

class GuideGenerator:

def __init__(self):

self.image_gen = ImageGenerator()

self.templates = self._load_templates()

def _load_templates(self):

"""加载指南模板"""

return {

"基础操作": {

"开关机": """

【开关机操作】

1. 开机:长按电源键3秒,看到品牌logo后松手

2. 关机:长按电源键,在弹出菜单中选择"关机"

3. 重启:长按电源键,选择"重启"

💡 小贴士:如果手机卡顿,可以尝试重启手机

""",

"屏幕解锁": """

【屏幕解锁方法】

1. 密码解锁:输入您设置的4-6位数字密码

2. 图案解锁:按设定好的图案连接圆点

3. 指纹解锁:将录入的手指放在指纹识别区域

4. 面部解锁:看向手机前置摄像头

⚠️ 注意:记住您设置的解锁方式,避免忘记

""",

"音量调节": """

【音量调节方法】

1. 按音量+键:增大音量

2. 按音量-键:减小音量

3. 进入设置→声音与振动,精细调节各音量

4. 通话时:使用通话界面的音量键调节听筒音量

🔊 建议:将铃声音量调至适中,既不会错过电话也不会太吵

"""

},

"社交应用": {

"微信使用": """

【微信基本操作】

1. 打开微信:点击绿色微信图标

2. 发送消息:进入聊天→点击输入框→输入文字→发送

3. 接听语音:点击语音消息即可播放

4. 视频通话:点击视频通话按钮

5. 发朋友圈:点击发现→朋友圈→右上角相机图标

📱 实用技巧:

- 长按语音消息可转文字

- 双击文字消息可快速回复

- 左滑聊天可置顶或删除

""",

"拍照分享": """

【拍照和分享照片】

1. 打开相机:点击相机图标

2. 拍照:对准目标,点击快门按钮

3. 查看照片:点击左下角缩略图

4. 分享照片:选择照片→分享按钮→选择分享方式

📸 拍照小贴士:

- 光线充足时照片更清晰

- 拍摄人像时距离保持1-2米

- 可以开启网格线辅助构图

"""

},

"支付功能": {

"微信支付": """

【微信支付使用方法】

1. 绑定银行卡:我→支付→钱包→银行卡→添加银行卡

2. 扫码支付:打开微信→扫一扫→扫描商家二维码

3. 出示付款码:我→支付→收付款→向商家出示二维码

4. 转账:聊天界面→+号→转账→输入金额→确认

💰 安全提醒:

- 不要向陌生人透露支付密码

- 定期检查账单记录

- 设置支付密码,不要用生日

""",

"支付宝使用": """

【支付宝基本操作】

1. 打开支付宝:点击蓝色支付宝图标

2. 扫码支付:首页→扫一扫

3. 付款码:首页→付钱

4. 生活缴费:首页→生活缴费

5. 转账:首页→转账

🔒 安全建议:

- 开启指纹/面容支付更安全

- 不要在公共WiFi下进行支付

- 及时更新支付宝版本

"""

},

"安全防护": {

"防诈骗": """

【防范电信诈骗】

1. 陌生来电要警惕,不轻易相信

2. 不随意点击短信链接

3. 不在电话中透露银行卡信息

4. 遇到可疑情况先挂断,咨询家人

5. 下载国家反诈中心APP

🚨 重要提醒:

- 银行不会电话索要验证码

- 中奖信息多数是诈骗

- 紧急情况先核实身份

""",

"隐私保护": """

【保护个人隐私】

1. 设置锁屏密码

2. 关闭不必要的定位服务

3. 谨慎授权APP权限

4. 定期清理浏览记录

5. 不随意连接免费WiFi

🛡️ 保护措施:

- 开启查找手机功能

- 定期备份重要数据

- 安装可靠的安全软件

"""

}

}

def generate_guide(self, phone_info, functions):

"""生成个性化使用指南"""

try:

guide_content = []

timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

# 添加封面信息

cover_section = {

"title": "📱 专属手机使用指南",

"content": f"""

手机型号:{phone_info}

生成时间:{timestamp}

适用人群:中老年用户

亲爱的用户,这份指南专为您定制,内容简洁易懂,

配有图解说明,助您轻松掌握手机使用技巧!

"""

}

guide_content.append(cover_section)

# 为每个选中的功能生成详细指南

for function in functions:

if function in self.templates:

for sub_function, content in self.templates[function].items():

section = {

"title": f"{function} - {sub_function}",

"content": content,

"images": self.image_gen.generate_images(function, sub_function)

}

guide_content.append(section)

# 添加总结部分

summary_section = {

"title": "📋 使用总结",

"content": """

恭喜您!通过以上学习,您已经掌握了基本的手机操作。

🎯 学习建议:

1. 每天练习10-15分钟

2. 从最常用的功能开始

3. 遇到问题不要着急,可以重复查看指南

4. 多向家人朋友请教

📞 求助渠道:

- 手机厂商客服热线

- 子女孙辈的帮助

- 社区老年大学课程

- 在线教程视频

祝您使用愉快,享受智能生活的便利!

"""

}

guide_content.append(summary_section)

return guide_content

except Exception as e:

print(f"生成指南时出错:{e}")

return None

3. 语音播放模块 (voice_player.py)

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

语音播放模块

负责将文本转换为语音并播放,支持语速调节

"""

import pyttsx3

import threading

import time

from queue import Queue

class VoicePlayer:

def __init__(self):

"""初始化语音引擎"""

try:

self.engine = pyttsx3.init()

self.setup_voice()

self.is_playing = False

self.current_text = ""

self.speed = 150 # 默认语速(词/分钟)

except Exception as e:

print(f"语音引擎初始化失败:{e}")

self.engine = None

def setup_voice(self):

"""配置语音参数,使其更适合老年人"""

if not self.engine:

return

try:

# 获取可用的语音

voices = self.engine.getProperty('voices')

# 优先选择中文语音

chinese_voice = None

for voice in voices:

if 'chinese' in voice.name.lower() or 'mandarin' in voice.name.lower():

chinese_voice = voice.id

break

if chinese_voice:

self.engine.setProperty('voice', chinese_voice)

# 设置语速(较慢,适合老年人)

self.engine.setProperty('rate', self.speed)

# 设置音量

self.engine.setProperty('volume', 0.9)

except Exception as e:

print(f"语音设置失败:{e}")

def text_to_speech(self, text, callback=None):

"""将文本转换为语音"""

if not self.engine:

print("❌ 语音引擎不可用")

return False

try:

# 分段播放长文本

sentences = self._split_text(text)

for sentence in sentences:

if not self.is_playing:

break

self.engine.say(sentence)

self.engine.runAndWait()

time.sleep(0.5) # 句子间停顿

if callback:

callback()

return True

except Exception as e:

print(f"语音播放失败:{e}")

return False

def _split_text(self, text):

"""将长文本分割成句子"""

# 按标点符号分割

import re

sentences = re.split(r'[。!?.!?]', text)

sentences = [s.strip() for s in sentences if s.strip()]

# 合并过短的句子

result = []

current_sentence = ""

for sentence in sentences:

if len(current_sentence + sentence) < 50: # 每句不超过50字

current_sentence += sentence + "。"

else:

if current_sentence:

result.append(current_sentence)

current_sentence = sentence + "。"

if current_sentence:

result.append(current_sentence)

return result

def play_guide(self, guide_content):

"""播放完整的指南内容"""

if not guide_content:

print("❌ 没有可播放的内容")

return

self.is_playing = True

try:

for section in guide_content:

if not self.is_playing:

break

print(f"\n🔊 正在播报:{section['title']}")

# 播放标题

self.text_to_speech(f"{section['title']}")

# 播放内容

if 'content' in section:

self.text_to_speech(section['content'])

# 询问是否继续

if section != guide_content[-1]: # 不是最后一节

continue_choice = input("\n按回车继续播放,输入 q 退出:")

if continue_choice.lower() == 'q':

break

if self.is_playing:

print("\n✅ 指南播放完成!")

except KeyboardInterrupt:

print("\n⏹️ 播放已停止")

finally:

self.is_playing = False

self.stop()

def stop(self):

"""停止播放"""

self.is_playing = False

if self.engine:

self.engine.stop()

def set_speed(self, speed):

"""设置语速"""

if self.engine and 100 <= speed <= 300:

self.speed = speed

self.engine.setProperty('rate', speed)

print(f"✅ 语速已设置为:{speed}词/分钟")

def adjust_speed_menu(self):

"""语速调节菜单"""

print("\n🎵 语速调节:")

print("1. 慢速 (120词/分钟)")

print("2. 正常 (150词/分钟)")

print("3. 快速 (180词/分钟)")

print("4. 自定义速度")

choice = input("请选择语速(1-4):")

speed_map = {'1': 120, '2': 150, '3': 180}

if choice in speed_map:

self.set_speed(speed_map[choice])

elif choice == '4':

try:

custom_speed = int(input("请输入语速(100-300):"))

self.set_speed(custom_speed)

except ValueError:

print("❌ 无效输入,使用默认语速")

self.set_speed(150)

4. 图片生成模块 (image_generator.py)

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

图片生成模块

负责生成示意图和操作截图说明

注:实际项目中可集成真实截图或使用绘图库生成示意图

"""

from PIL import Image, ImageDraw, ImageFont

import io

import base64

class ImageGenerator:

def __init__(self):

"""初始化图片生成器"""

try:

# 尝试加载字体,如果失败则使用默认字体

self.font = ImageFont.load_default()

# 在实际项目中,这里应该加载中文字体文件

except Exception as e:

print(f"字体加载失败:{e}")

self.font = None

def generate_images(self, function, sub_function):

"""为指定功能生成相关图片"""

images = []

try:

if function == "基础操作":

if sub_function == "开关机":

images.append(self._create_power_button_image())

elif sub_function == "屏幕解锁":

images.append(self._create_unlock_pattern_image())

elif sub_function == "音量调节":

images.append(self._create_volume_control_image())

elif function == "社交应用":

if sub_function == "微信使用":

images.append(self._create_wechat_interface_image())

elif sub_function == "拍照分享":

images.append(self._create_camera_app_image())

elif function == "支付功能":

if sub_function == "微信支付":

images.append(self._create_payment_qr_image())

elif sub_function == "支付宝使用":

images.append(self._create_alipay_interface_image())

elif function == "安全防护":

if sub_function == "防诈骗":

images.append(self._create_safety_tips_image())

elif sub_function == "隐私保护":

images.append(self._create_privacy_settings_image())

except Exception as e:

print(f"生成图片时出错:{e}")

return images

def _create_power_button_image(self):

"""创建电源按钮示意图"""

img = Image.new('RGB', (300, 200), color='white')

draw = ImageDraw.Draw(img)

# 绘制手机轮廓

draw.rectangle([50, 30, 250, 170], outline='black', width=2)

# 绘制电源按钮

draw.rectangle([230, 80, 240, 120], fill='gray', outline='black')

draw.text((245, 95), "电源键", fill='black')

# 添加说明文字

draw.text((20, 185), "长按电源键3秒开机", fill='blue')

return self._image_to_base64(img)

def _create_unlock_pattern_image(self):

"""创建解锁图案示意图"""

img = Image.new('RGB', (300, 300), color='white')

draw = ImageDraw.Draw(img)

# 绘制九宫格

positions = [(75, 75), (150, 75), (225, 75),

(75, 150), (150, 150), (225, 150),

(75, 225), (150, 225), (225, 225)]

# 画圆点

for pos in positions:

draw.ellipse([pos[0]-15, pos[1]-15, pos[0]+15, pos[1]+15],

outline='blue', width=2)

# 绘制示例连线

draw.line([positions[0], positions[1], positions[2], positions[5], positions[8]],

fill='red', width=3)

draw.text((20, 280), "按设定图案连接圆点", fill='blue')

return self._image_to_base64(img)

def _create_wechat_interface_image(self):

"""创建微信界面示意图"""

img = Image.new('RGB', (300, 400), color='white')

draw = ImageDraw.Draw(img)

# 顶部状态栏

draw.rectangle([0, 0, 300, 30], fill='green')

draw.text((10, 8), "微信", fill='white')

# 聊天列表

chat_items = [

("张三", "你好,最近怎么样?", "09:30"),

("李四", "[语音]", "昨天"),

("王五", "晚上一起吃饭吧", "周三")

]

y_pos = 50

for name, msg, time in chat_items:

# 头像

draw.ellipse([20, y_pos, 60, y_pos+40], outline='gray')

# 姓名

draw.text((70, y_pos+5), name, fill='black')

# 消息预览

draw.text((70, y_pos+20), msg, fill='gray')

# 时间

draw.text((220, y_pos+5), time, fill='gray')

y_pos += 60

draw.text((20, 350), "点击聊天进入对话", fill='blue')

return self._image_to_base64(img)

def _create_payment_qr_image(self):

"""创建支付二维码示意图"""

img = Image.new('RGB', (250, 300), color='white')

draw = ImageDraw.Draw(img)

# 顶部

draw.rectangle([0, 0, 250, 40], fill='green')

draw.text((20, 12), "微信支付", fill='white')

# 二维码区域

draw.rectangle([50, 80, 200, 230], outline='black', width=2)

# 绘制模拟二维码

for i in range(0, 150, 10):

for j in range(0, 150, 10):

if (i//10 + j//10) % 2 == 0:

draw.rectangle([50+i, 80+j, 60+i, 90+j], fill='black')

# 提示文字

draw.text((30, 250), "向商家出示此二维码付款", fill='blue')

draw.text((30, 270), "金额:¥25.80", fill='red', font_size=16)

return self._image_to_base64(img)

def _image_to_base64(self, img):

"""将PIL图像转换为base64字符串"""

buffer = io.BytesIO()

img.save(buffer, format='PNG')

img_str = base64.b64encode(buffer.getvalue()).decode()

return f"data:image/png;base64,{img_str}"

# 其他图片生成方法的占位符实现

def _create_volume_control_image(self):

return "placeholder_volume_image"

def _create_camera_app_image(self):

return "placeholder_camera_image"

def _create_alipay_interface_image(self):

return "placeholder_alipay_image"

def _create_safety_tips_image(self):

return "placeholder_safety_image"

def _create_privacy_settings_image(self):

return "placeholder_privacy_image"

5. 配置文件 (config.py)

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

配置文件

存储支持的手机型号、指南模板等配置信息

"""

# 支持的手机品牌和型号

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询