feat: 添加启动提示声音

This commit is contained in:
DongShengWu 2026-01-02 07:38:17 +08:00
parent 91efe70da0
commit 9f2f086cdf
6 changed files with 55 additions and 30 deletions

View File

@ -11,11 +11,11 @@ from state_detection import StateDetector
# ========== 配置参数 ==========
# WiFi配置
WIFI_SSID = "ZTE_969121"
WIFI_PASSWORD = None
WIFI_SSID = "dongshengwu"
WIFI_PASSWORD = "wds666666"
# 服务器配置
SERVER_HOST = "192.168.0.21"
SERVER_HOST = "172.20.10.9"
SERVER_PORT = 8081
API_PATH = "/api/detection/analyze"

View File

@ -217,9 +217,11 @@ class AgentClientHTTP:
if __name__ == "__main__":
# ========== CONFIG ==========
WIFI_SSID = "dongshengwu"
# WIFI_SSID = "dongshengwu"
WIFI_SSID = "ZTE_969121"
WIFI_PASSWORD = "wds666666"
SERVER_HOST = "172.20.10.2"
# SERVER_HOST = "172.20.10.2"
SERVER_HOST = "192.168.0.93"
SERVER_PORT = 8000
# ============================

View File

@ -1,39 +1,59 @@
# play mp4 file example
# audio input and output example
#
# Note: You will need an SD card to run this example.
#
# You can load local files to play. The current version only supports MP4 format, video supports 264/265, and audio supports g711a/g711u.
# You can play wav files or capture audio to save as wav
from media.player import * #导入播放器模块用于播放mp4文件
import os
from media.media import * # 导入media模块用于初始化vb buffer
from media.pyaudio import * # 导入pyaudio模块用于采集和播放音频
import media.wave as wave # 导入wav模块用于保存和加载wav音频文件
start_play = False #播放结束flag
def player_event(event,data):
global start_play
if(event == K_PLAYER_EVENT_EOF): #播放结束标识
start_play = False #设置播放结束标识
def play_mp4_test(filename):
global start_play
player=Player() #创建播放器对象
player.load(filename) #加载mp4文件
player.set_event_callback(player_event) #设置播放器事件回调
player.start() #开始播放
start_play = True
#等待播放结束
def exit_check():
try:
while(start_play):
time.sleep(0.1)
os.exitpoint()
except KeyboardInterrupt as e:
print("user stop: ", e)
except BaseException as e:
sys.print_exception(e)
return True
return False
def play_audio(filename):
try:
wf = wave.open(filename, 'rb') # 打开wav文件
CHUNK = int(wf.get_framerate() / 25) # 设置音频chunk值
p = PyAudio()
p.initialize(CHUNK) # 初始化PyAudio对象
MediaManager.init() # vb buffer初始化
# 创建音频输出流设置的音频参数均为wave中获取到的参数
stream = p.open(format=p.get_format_from_width(wf.get_sampwidth()),
channels=wf.get_channels(),
rate=wf.get_framerate(),
output=True, frames_per_buffer=CHUNK)
data = wf.read_frames(CHUNK) # 从wav文件中读取数一帧数据
while data:
stream.write(data) # 将帧数据写入到音频输出流中
data = wf.read_frames(CHUNK) # 从wav文件中读取数一帧数据
if exit_check():
break
except BaseException as e:
print(f"Exception {e}")
finally:
stream.stop_stream() # 停止音频输出流
stream.close() # 关闭音频输出流
p.terminate() # 释放音频对象
wf.close() # 关闭wav文件
MediaManager.deinit() # 释放vb buffer
player.stop() #停止播放
print("play over")
if __name__ == "__main__":
os.exitpoint(os.EXITPOINT_ENABLE)
play_mp4_test("/sdcard/logo_3s.mp4")#播放mp4文件
print("play_audio sample start")
play_audio('/sdcard/hello.wav') # 播放wav文件
print("play_audio sample done")

BIN
k230/hello.wav Normal file

Binary file not shown.

BIN
k230/hello_24k.wav Normal file

Binary file not shown.

View File

@ -0,0 +1,3 @@
# 查看/sdcard下的文件
import os
print(os.listdir('/sdcard'))