数字投屏叫号器-发射端python窗口定制

窗口

本系列前章介绍,叫号器的显示端,完成了视频音频的形成和传输的介绍。本章节开始定制小窗口。

最终实现,处于桌面最前端,发送指令,集合前篇即可完成:

  • 处理本地text.txt更新,随之被rtsp采集
    ffmpeg 参数: -vf "drawtext=textfile=text.txt:reload=1:x=10:y=10:fontsize=20:fontcolor=red:fontfile=simhei.ttf"
  • 播报语音 透过虚拟声卡发送到rtsp
    ffmpeg 参数:-f dshow -i audio="CABLE Output (VB-Audio Virtual Cable)" -acodec aac -b:a 128k

集成运行的要点

  1. 指定声卡为虚拟声卡。
  2. 运行mediamtx免费的流媒体服务器,
  3. 本网络有一台可接受投屏,并支持rtsp流的显示设备android推荐airReciever

补充:

ffmpeg进程需要常驻后台,有断开检测。重启后需要再次推送。

推流 的python任务,需要检测播放状态。dlna是播放就结束。airplay是播放后等待。需要选择一种。

主要窗体代码:

bash 复制代码
import tkinter as tk
import pyttsx3
from tkinter import messagebox

import asyncio
 
# 数值验证函数
def say(text):
        eng=pyttsx3.init()
        eng.say(text)
        eng.runAndWait()
        update_status(f"{saytext}-播放结束")

 

def validate_num_input(text):
    if text == "":  # 允许清空输入框
        return True
    try:
        int(text)
        return True
    except ValueError:
        return False

# 数值操作函数
def increase():
    try:
        current = int(num_entry.get())
    except ValueError:
        current = 0
    num_entry.delete(0, tk.END)
    num_entry.insert(0, str(current + 1))

def decrease():
    try:
        current = int(num_entry.get())
    except ValueError:
        current = 0
    num_entry.delete(0, tk.END)
    num_entry.insert(0, str(current - 1))

# 数据发送函数
def send_data():
    global saytext
    text = text_entry.get()
    number = num_entry.get()
    saytext=text.replace('n',number)
    update_status(f"{saytext}-准备播放")
    
def update_status(new_status):
        # 更新状态栏的文本内容
        global status_bar
        status_bar.config(text=new_status)
        # 刷新界面以立即显示更新
        status_bar.update_idletasks()    
    
    # messagebox.showinfo(
    #     "发送结果",
    #     f"文本内容:{text}\n数字数值:{number}\n说出文本:{saytext}",
        
    #     parent=root
    # )
 
# 创建主窗口
root = tk.Tk()
root.title("控制面板")
root.geometry("250x150")

# 输入验证注册
validate_cmd = root.register(validate_num_input)

# 控件创建
tk.Label(root, text="文本输入:").grid(row=0, column=0, padx=1, pady=1, sticky="w")
text_entry = tk.Entry(root)
text_entry.grid(row=0, column=1, padx=1, pady=1, columnspan=2)
default_text = "请n号就诊"
text_entry.insert(tk.END, default_text)
tk.Label(root, text="数字输入:").grid(row=1, column=0, padx=1, pady=1, sticky="w")
num_entry = tk.Entry(
    root,
    validate="key",
    validatecommand=(validate_cmd, "%P")
)
num_entry.grid(row=1, column=1, padx=2, pady=2, columnspan=2)
num_entry.insert(0, "0")  # 设置初始值

# 按钮区域
button_frame = tk.Frame(root)
button_frame.grid(row=2, column=0, columnspan=3, pady=10)
tk.Button(button_frame, text="-", command=decrease).pack(side="left", padx=1)
tk.Button(button_frame, text="+", command=increase).pack(side="left", padx=1)

button=tk.Button(button_frame, text="发送", command=send_data,bg="white")
button.pack(side="left", padx=1,pady=2)
 
status_bar = tk.Label(root, text="初始状态")
status_bar.grid(row=3, column=1, padx=1, pady=1, sticky="w")
# 模拟一个异步函数
saytext=None
async def async_task():
    global saytext
    while True:
    #    print("异步任务正在运行...")
        await asyncio.sleep(1)
        if saytext:
            say(saytext)
            saytext=None

# 将异步任务与 Tkinter 集成
def run_async_task(root):
    loop = asyncio.get_event_loop()
    task = loop.create_task(async_task())

    def update():
        loop.stop()
        loop.run_forever()
        root.after(100, update)

    root.after(100, update)

run_async_task(root)
root.wm_attributes("-topmost", 1)
root.mainloop()

bilibile com title-投屏器的发送端 视频来源

相关推荐
System_sleep4 分钟前
win11编译llama_cpp_python cuda128 RTX30/40/50版本
windows·python·llama·cuda
小宁爱Python19 分钟前
Python从入门到精通1:FastAPI
python·beautifulsoup·numpy·fastapi
叶域21 分钟前
正则表达式(复习)
大数据·python·正则表达式
qq_4476630537 分钟前
《Spring日志整合与注入技术:从入门到精通》
java·开发语言·后端·spring
蜡笔小新星43 分钟前
OpenCV中文路径图片读写终极指南(Python实现)
开发语言·人工智能·python·opencv·计算机视觉
七七知享1 小时前
2024 Qiniu 跨平台 Qt 高级开发全解析
开发语言·qt·零基础·操作系统·跨平台·qt5·精通
yuanpan1 小时前
conda创建Python虚拟环境的原理
python·conda
java_python源码1 小时前
【2025】基于python+django的考研自习室预约系统(源码、万字文档、图文修改、调试答疑)
python·考研·django
脏脏a1 小时前
C 语言分支与循环:构建程序逻辑的基石
c语言·开发语言
火车叼位1 小时前
从Anaconda迁移至UV技术实践与解析
python