Skip to content

Commit abb4147

Browse files
Merge pull request #19 from yunxinusecase/v1.1.5
V1.1.5
2 parents 9cae47b + 09cded3 commit abb4147

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2756
-318
lines changed

build.ps1

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
# 获取脚本的参数
3+
$arguments = $args
4+
Write-Host "args: $args"
5+
6+
# 初始化变量
7+
$espIdfPath = ""
8+
$projectPath = ""
9+
$otherParams = @()
10+
11+
# 遍历参数
12+
foreach ($arg in $arguments) {
13+
if ($arg -match "^--espIdfPath=") {
14+
# 提取 espIdfPath 的值
15+
$espIdfPath = $arg -replace "^--espIdfPath=", ""
16+
} elseif ($arg -match "^--projectPath=") {
17+
# 提取 projectPath 的值
18+
$projectPath = $arg -replace "^--projectPath=", ""
19+
} else {
20+
# 将其他参数添加到数组中
21+
$otherParams += $arg
22+
}
23+
}
24+
25+
# 检查 espIdfPath 是否为空,如果为空则使用默认值
26+
if ([string]::IsNullOrEmpty($espIdfPath)) {
27+
$espIdfPath = "C:/Users/hzgaoqi1/esp/v5.4.1/esp-idf"
28+
}
29+
if ([string]::IsNullOrEmpty($projectPath)) {
30+
$projectPath = (Get-Location).Path
31+
}
32+
33+
# 打印参数值以调试
34+
Write-Host "Debug Information:"
35+
Write-Host "espIdfPath: $espIdfPath"
36+
Write-Host "projectPath: $projectPath"
37+
Write-Host "otherParams: $otherParams"
38+
39+
# 设置环境变量
40+
$env:IDF_PATH = $espIdfPath
41+
$env:PATH = "$env:PATH;$env:IDF_PATH/tools"
42+
43+
# 激活 ESP-IDF 环境
44+
. "$env:IDF_PATH/export.ps1"
45+
46+
# 构造 Python 命令
47+
$pythonCommand = "python $projectPath/build.py"
48+
foreach ($arg in $args) {
49+
$pythonCommand += " $arg"
50+
}
51+
52+
# 打印构造的 Python 命令以调试
53+
Write-Host "Executing command: $pythonCommand"
54+
55+
# 运行 Python 编译脚本并捕获输出和退出状态码
56+
$process = Start-Process -FilePath "python" -ArgumentList "$projectPath/build.py", "$otherParams" -PassThru -NoNewWindow -Wait
57+
$exitCode = $process.ExitCode
58+
59+
# 打印退出状态码
60+
Write-Host "Exit code: $exitCode"
61+
62+
# 退出脚本并返回状态码
63+
exit $exitCode

build.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import os
2+
import shutil
3+
import subprocess
4+
import argparse
5+
import platform
6+
7+
# 设置 ESP-IDF 路径
8+
esp_idf_path = {
9+
"Windows": "C:/Users/hzgaoqi1/esp/v5.4.1/esp-idf",
10+
"Darwin": "/path/to/esp-idf" # macOS路径,需要根据实际情况修改
11+
}
12+
13+
def run_command(command, cwd=None):
14+
"""运行命令并捕获输出"""
15+
try:
16+
subprocess.run(command, check=True, cwd=cwd, shell=True)
17+
except subprocess.CalledProcessError as e:
18+
print(f"Error: {e}")
19+
exit(1)
20+
21+
def activate_espidf_env(esp_idf_path):
22+
"""激活ESP-IDF环境"""
23+
if platform.system() == "Windows":
24+
# # 直接在Python中设置环境变量
25+
# os.environ["IDF_PATH"] = esp_idf_path["Windows"]
26+
# os.environ["PATH"] = f"{os.environ['PATH']};{os.path.join(esp_idf_path['Windows'], 'tools')}"
27+
print(f"Activating ESP-IDF environment for Windows at build.ps1")
28+
elif platform.system() == "Darwin": # macOS
29+
# os.environ["IDF_PATH"] = esp_idf_path["Darwin"]
30+
# os.environ["PATH"] = f"{os.environ['PATH']}:{os.path.join(esp_idf_path['Darwin'], 'tools')}"
31+
print(f"Activating ESP-IDF environment for Mac at build.sh")
32+
33+
def build_project(target, build_dir, project_path, esp_idf_path):
34+
"""编译项目"""
35+
print(f"Compiling {target} project...")
36+
# 删除旧的 sdkconfig 文件
37+
sdkconfig_path = os.path.join(project_path, "sdkconfig")
38+
if os.path.exists(sdkconfig_path):
39+
os.remove(sdkconfig_path)
40+
41+
# 根据目标芯片复制默认的 sdkconfig 文件
42+
sdkconfig_defaults_path = os.path.join(project_path, f"sdkconfig.defaults.{target}")
43+
if not os.path.exists(sdkconfig_defaults_path):
44+
print(f"Error: sdkconfig.defaults.{target} not found in {project_path}")
45+
exit(1)
46+
shutil.copy(sdkconfig_defaults_path, sdkconfig_path)
47+
48+
# 激活 ESP-IDF 环境
49+
activate_espidf_env(esp_idf_path)
50+
51+
# 运行编译命令
52+
build_command = f"idf.py -B {build_dir} -DIDF_TARGET={target} build"
53+
run_command(build_command, cwd=project_path)
54+
print(f"{target} compilation completed successfully. Output in {build_dir}")
55+
56+
def main():
57+
parser = argparse.ArgumentParser(description="Build ESP-IDF projects for different targets.")
58+
parser.add_argument("--esp32s3", action="store_true", help="Build for ESP32-S3")
59+
parser.add_argument("--esp32c3", action="store_true", help="Build for ESP32-C3")
60+
parser.add_argument("--all", action="store_true", help="Build for both ESP32-S3 and ESP32-C3 (default)")
61+
62+
args = parser.parse_args()
63+
64+
# 设置默认行为为 --all
65+
if not (args.esp32s3 or args.esp32c3 or args.all):
66+
args.all = True
67+
68+
# 设置路径
69+
script_dir = os.path.dirname(os.path.abspath(__file__))
70+
project_path = script_dir
71+
72+
# # 删除旧的 out 目录
73+
# out_dir = os.path.join(script_dir, "out")
74+
# if os.path.exists(out_dir):
75+
# shutil.rmtree(out_dir)
76+
# os.makedirs(out_dir)
77+
78+
try:
79+
if args.all or args.esp32s3:
80+
build_dir = os.path.join(script_dir, "out", "esp32s3")
81+
build_project("esp32s3", build_dir, project_path, esp_idf_path)
82+
83+
if args.all or args.esp32c3:
84+
build_dir = os.path.join(script_dir, "out", "esp32c3")
85+
build_project("esp32c3", build_dir, project_path, esp_idf_path)
86+
except Exception as e:
87+
print(f"Error: {e}")
88+
exit(1)
89+
90+
if __name__ == "__main__":
91+
main()

build.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
# 获取脚本的参数
4+
arguments=("$@")
5+
echo "args: ${arguments[@]}"
6+
7+
# 初始化变量
8+
espIdfPath=""
9+
projectPath=""
10+
otherParams=()
11+
12+
# 遍历参数
13+
for arg in "${arguments[@]}"; do
14+
if [[ $arg =~ ^--espIdfPath= ]]; then
15+
# 提取 espIdfPath 的值
16+
espIdfPath="${arg#*=}"
17+
elif [[ $arg =~ ^--projectPath= ]]; then
18+
# 提取 projectPath 的值
19+
projectPath="${arg#*=}"
20+
else
21+
# 将其他参数添加到数组中
22+
otherParams+=("$arg")
23+
fi
24+
done
25+
26+
# 检查 espIdfPath 是否为空,如果为空则使用默认值
27+
if [ -z "$espIdfPath" ]; then
28+
espIdfPath="/Users/yunxin/project/esp/esp-idf"
29+
fi
30+
31+
# 检查 projectPath 是否为空,如果为空则使用当前目录
32+
if [ -z "$projectPath" ]; then
33+
projectPath="$(pwd)"
34+
fi
35+
36+
# 打印参数值以调试
37+
echo "Debug Information:"
38+
echo "espIdfPath: $espIdfPath"
39+
echo "projectPath: $projectPath"
40+
echo "otherParams: ${otherParams[@]}"
41+
42+
# 设置环境变量
43+
export IDF_PATH="$espIdfPath"
44+
export PATH="$PATH:$IDF_PATH/tools"
45+
46+
# 激活 ESP-IDF 环境
47+
cd $IDF_PATH
48+
. ./export.sh
49+
cd -
50+
51+
# 构造 Python 命令
52+
pythonCommand="python $projectPath/build.py"
53+
for arg in "${otherParams[@]}"; do
54+
pythonCommand+=" $arg"
55+
done
56+
57+
# 打印构造的 Python 命令以调试
58+
echo "Executing command: $pythonCommand"
59+
60+
# 运行 Python 编译脚本并捕获输出和退出状态码
61+
python $projectPath/build.py "${otherParams[@]}"
62+
exitCode=$?
63+
64+
# 打印退出状态码
65+
echo "Exit code: $exitCode"
66+
67+
# 退出脚本并返回状态码
68+
exit $exitCode

components/nertc_sdk/include/nertc_sdk.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _NERTC_SDK_H_
2-
#define _NERTC_SDK_H_
1+
#ifndef __NERTC_SDK_H__
2+
#define __NERTC_SDK_H__
33

44
#include "nertc_sdk_event.h"
55
#include "nertc_sdk_error.h"
@@ -52,9 +52,9 @@ NERTC_SDK_API int nertc_init(nertc_sdk_engine_t engine);
5252
* - 非0:失败 <br>
5353
*/
5454
NERTC_SDK_API int nertc_join(nertc_sdk_engine_t engine,
55-
const char* channel_name,
56-
const char * token,
57-
uint64_t uid);
55+
const char* channel_name,
56+
const char * token,
57+
uint64_t uid);
5858

5959
/**
6060
* @brief 离开房间
@@ -163,6 +163,14 @@ NERTC_SDK_API int nertc_stop_ai(nertc_sdk_engine_t engine);
163163
*/
164164
NERTC_SDK_API int nertc_ai_manual_interrupt(nertc_sdk_engine_t engine);
165165

166+
/**
167+
* @brief 挂断电话
168+
* @param engine 通过 nertc_create_engine 创建且通过 nertc_init 初始化之后的引擎实例
169+
* @return 方法调用结果:<br>
170+
* - 0:成功 <br>
171+
* - 非0:失败 <br>
172+
*/
173+
NERTC_SDK_API int nertc_ai_hang_up(nertc_sdk_engine_t engine);
166174

167175
#ifdef __cplusplus
168176
}

components/nertc_sdk/include/nertc_sdk_define.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ extern "C" {
1010
/** token 最大长度 */
1111
#define kNERtcMaxTokenLength 256
1212

13+
typedef enum {
14+
NERTC_SDK_DEVICE_LEVEL_NORMAL = 0,
15+
NERTC_SDK_DEVICE_LEVEL_LOW = 1,
16+
NERTC_SDK_DEVICE_LEVEL_HIGH = 2
17+
} nertc_sdk_device_level_e;
18+
1319
typedef enum {
1420
NERTC_SDK_LOG_NONE = 0,
1521
NERTC_SDK_LOG_ERROR = 1,
@@ -34,6 +40,7 @@ typedef enum {
3440
} nertc_sdk_user_type_e;
3541

3642
typedef enum {
43+
NERTC_SDK_MEDIA_UNKNOWN = -1,
3744
NERTC_SDK_MEDIA_MAIN_AUDIO = 0,
3845
NERTC_SDK_MEDIA_SUB_AUDIO = 1,
3946
NERTC_SDK_MEDIA_MAIN_VIDEO = 2,
@@ -57,6 +64,20 @@ typedef enum {
5764
NERTC_SDK_ASR_CAPTION_STATE_STOPPED = 3
5865
} nertc_sdk_asr_caption_state_e;
5966

67+
typedef struct nertc_sdk_optional_config {
68+
nertc_sdk_device_level_e device_performance_level;
69+
bool enable_server_aec;
70+
char* custom_config;
71+
} nertc_sdk_optional_config_t;
72+
73+
typedef struct nertc_sdk_licence_config {
74+
const char* license; // licence
75+
} nertc_sdk_licence_config_t;
76+
77+
typedef struct nertc_sdk_log_config {
78+
nertc_sdk_log_level_e log_level;
79+
} nertc_sdk_log_config_t;
80+
6081
typedef struct nertc_sdk_user_info {
6182
/**
6283
* @if Chinese
@@ -105,7 +126,7 @@ typedef struct nertc_sdk_audio_frame {
105126
nertc_sdk_audio_config_t config;
106127
/** 音频帧数据 */
107128
void* data;
108-
/** 音频帧数据的长度 */
129+
/** 音频帧数据int16的长度 */
109130
int length;
110131
} nertc_sdk_audio_frame_t;
111132

@@ -165,4 +186,4 @@ typedef struct nertc_sdk_ai_data_result {
165186
}
166187
#endif
167188

168-
#endif // __NERTC_SDK_DEFINE_H__
189+
#endif // __NERTC_SDK_DEFINE_H__

components/nertc_sdk/include/nertc_sdk_error.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ typedef enum {
4646
/* Invalid state */
4747
NERTC_SDK_ERR_INVALID_STATE = 30005,
4848

49+
/* 许可证不合法 */
50+
NERTC_SDK_ERR_LICENSE_ILLEGAL = 30060,
51+
52+
/* 许可证不存在 */
53+
NERTC_SDK_ERR_LICENSE_NOT_EXIST = 30061,
54+
55+
/* 许可证校验失败 */
56+
NERTC_SDK_ERR_LICENSE_CHECK_FAILED = 30062,
57+
58+
/* 许可证已过期 */
59+
NERTC_SDK_ERR_LICENSE_EXPIRED = 30063,
60+
61+
/* 许可证未激活 */
62+
NERTC_SDK_ERR_LICENSE_NOT_ACTIVATED = 30064,
63+
4964
/** 用户未找到 */
5065
NERTC_SDK_ERR_USER_NOT_FOUND = 30105,
5166

@@ -59,8 +74,7 @@ typedef enum {
5974
NERTC_SDK_ERR_KICKED_BY_SERVER = 30206,
6075

6176
/** 房间已被关闭 */
62-
NERTC_SDK_ERR_KICKED_BY_CHANNEL_CLOSED = 30207,
63-
77+
NERTC_SDK_ERR_KICKED_BY_CHANNEL_CLOSED = 30207,
6478
} nertc_sdk_error_code_e;
6579

6680
#ifdef __cplusplus

0 commit comments

Comments
 (0)