diff --git a/k230/05test_state_detection.py b/k230/05test_state_detection.py index f5d9667..19c6cb9 100644 --- a/k230/05test_state_detection.py +++ b/k230/05test_state_detection.py @@ -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" diff --git a/k230/agent_client_http.py b/k230/agent_client_http.py index 77c21e8..277ff78 100644 --- a/k230/agent_client_http.py +++ b/k230/agent_client_http.py @@ -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 # ============================ diff --git a/k230/boot.py b/k230/boot.py index 0888531..ec1612a 100644 --- a/k230/boot.py +++ b/k230/boot.py @@ -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() + 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") diff --git a/k230/hello.wav b/k230/hello.wav new file mode 100644 index 0000000..7e07410 Binary files /dev/null and b/k230/hello.wav differ diff --git a/k230/hello_24k.wav b/k230/hello_24k.wav new file mode 100644 index 0000000..e68783a Binary files /dev/null and b/k230/hello_24k.wav differ diff --git a/k230/test.py b/k230/test.py index e69de29..ab2ffa4 100644 --- a/k230/test.py +++ b/k230/test.py @@ -0,0 +1,3 @@ +# 查看/sdcard下的文件 +import os +print(os.listdir('/sdcard'))