diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..5b1982fcd --- /dev/null +++ b/.clang-format @@ -0,0 +1,88 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +Cpp11BracedListStyle: true +AccessModifierOffset: -4 +AlignConsecutiveMacros: true +AlignTrailingComments: false +AlignAfterOpenBracket: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AlignArrayOfStructures: Left +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: None +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterExternBlock: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +# BraceBreakingStyle: Attach +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CommentPragmas: '^[^ ]' +CompactNamespaces: false +ContinuationIndentWidth: 8 +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +InsertTrailingCommas: Wrapped +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never \ No newline at end of file diff --git a/.github/workflows/c-codestyle.yml b/.github/workflows/c-codestyle.yml new file mode 100644 index 000000000..74f9c8498 --- /dev/null +++ b/.github/workflows/c-codestyle.yml @@ -0,0 +1,32 @@ +name: C Codestyle + +on: + workflow_dispatch: + push: + branches: [ master ] + paths: + - '**/*.c' + - '.github/workflows/c-codestyle.yml' + pull_request: + branches: [ master, 'v[0-9]+.[0-9]+' ] + paths: + - '**/*.c' + - '.github/workflows/c-codestyle.yml' + +jobs: + check-c-codestyle: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install dependencies + run: sudo apt install clang-format + + - name: Check c codestyle + run: python3 resources/.lint/c/formatter.py -c -v \ No newline at end of file diff --git a/.github/workflows/dotnet-demos.yml b/.github/workflows/dotnet-demos.yml index e1efe3788..1a9ae51bf 100644 --- a/.github/workflows/dotnet-demos.yml +++ b/.github/workflows/dotnet-demos.yml @@ -20,34 +20,85 @@ defaults: working-directory: demo/dotnet/PicovoiceDemo jobs: - build-micdemo: - runs-on: ubuntu-latest + build-github-hosted: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + include: + - os: ubuntu-latest + platform: linux + - os: windows-latest + platform: windows + - os: macos-latest + platform: mac steps: - uses: actions/checkout@v3 with: submodules: recursive - - name: Setup .NET + - name: Set up .NET 6.0 uses: actions/setup-dotnet@v3 with: dotnet-version: 6.0.x + - name: Package restore + run: dotnet restore + - name: Dotnet build micdemo run: dotnet build -c MicDemo.Release - build-filedemo: - runs-on: ubuntu-latest + - name: Dotnet build filedemo + run: dotnet build -c FileDemo.Release + + - name: Run Dotnet filedemo + run: dotnet run -c FileDemo.Release -- + --input_audio_path ../../../resources/audio_samples/picovoice-coffee.wav + --access_key ${{secrets.PV_VALID_ACCESS_KEY}} + --keyword_path ../../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + --context_path ../../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn + + build-self-hosted: + runs-on: ${{ matrix.machine }} + + strategy: + matrix: + machine: [rpi2, rpi3-32, rpi3-64, rpi4-32, rpi4-64, jetson, beaglebone] + include: + - machine: rpi2 + platform: raspberry-pi + - machine: rpi3-32 + platform: raspberry-pi + - machine: rpi3-64 + platform: raspberry-pi + - machine: rpi4-32 + platform: raspberry-pi + - machine: rpi4-64 + platform: raspberry-pi + - machine: jetson + platform: jetson + - machine: beaglebone + platform: beaglebone steps: - uses: actions/checkout@v3 with: submodules: recursive - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 6.0.x + - name: Package restore + run: dotnet restore + + - name: Dotnet build micdemo + run: dotnet build -c MicDemo.Release - name: Dotnet build filedemo run: dotnet build -c FileDemo.Release + + - name: Run Dotnet filedemo + run: dotnet run -c FileDemo.Release -- + --input_audio_path ../../../resources/audio_samples/picovoice-coffee.wav + --access_key ${{secrets.PV_VALID_ACCESS_KEY}} + --keyword_path ../../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + --context_path ../../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn \ No newline at end of file diff --git a/.github/workflows/flutter-demos.yml b/.github/workflows/flutter-demos.yml new file mode 100644 index 000000000..25a0589cb --- /dev/null +++ b/.github/workflows/flutter-demos.yml @@ -0,0 +1,83 @@ +name: Flutter + +on: + workflow_dispatch: + push: + branches: [ master ] + paths: + - '.github/workflows/flutter.yml' + - 'demo/flutter/**' + - '!demo/flutter/README.md' + pull_request: + branches: [ master, 'v[0-9]+.[0-9]+' ] + paths: + - '.github/workflows/flutter.yml' + - 'demo/flutter/**' + - '!demo/flutter/README.md' + +defaults: + run: + working-directory: demo/flutter + +jobs: + build-android: + name: Build Android demo + runs-on: ubuntu-latest + strategy: + matrix: + flutter-version: ['2.8.1', '3.0.4'] + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Install Flutter ${{ matrix.flutter-version }} + uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ matrix.flutter-version }} + + - name: Install dependencies + run: flutter pub get + + - name: Prepare demo + run: dart scripts/prepare_demo.dart en + + - name: Build + run: flutter build apk + + build-ios: + name: Build iOS demo + runs-on: macos-11 + strategy: + matrix: + flutter-version: ['2.8.1', '3.0.4'] + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install Flutter ${{ matrix.flutter-version }} + uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ matrix.flutter-version }} + architecture: x64 + + - name: Update Cocoapods repo + run: pod repo update + + - name: Install dependencies + run: flutter pub get + + - name: Prepare demo + run: dart scripts/prepare_demo.dart en + + - name: Build + run: flutter build ios --release --no-codesign diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index 7070c0907..f2621ecae 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -26,38 +26,6 @@ defaults: working-directory: demo/flutter jobs: - build-android: - name: Build Android demo - runs-on: ubuntu-latest - strategy: - matrix: - flutter-version: ['2.8.1', '3.0.4'] - - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - - - name: Install Flutter ${{ matrix.flutter-version }} - uses: subosito/flutter-action@v2 - with: - flutter-version: ${{ matrix.flutter-version }} - - - name: Install dependencies - run: flutter pub get - - - name: Prepare demo - run: dart scripts/prepare_demo.dart en - - - name: Build - run: flutter build apk - test-android: name: Test Android runs-on: pv-android @@ -83,36 +51,6 @@ jobs: - name: Run integration tests run: flutter test integration_test - build-ios: - name: Build iOS demo - runs-on: macos-11 - strategy: - matrix: - flutter-version: ['2.8.1', '3.0.4'] - - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Install Flutter ${{ matrix.flutter-version }} - uses: subosito/flutter-action@v2 - with: - flutter-version: ${{ matrix.flutter-version }} - architecture: x64 - - - name: Update Cocoapods repo - run: pod repo update - - - name: Install dependencies - run: flutter pub get - - - name: Prepare demo - run: dart scripts/prepare_demo.dart en - - - name: Build - run: flutter build ios --release --no-codesign - test-ios: name: Test iOS runs-on: pv-ios diff --git a/.github/workflows/ios-demos.yml b/.github/workflows/ios-demos.yml new file mode 100644 index 000000000..f618bec97 --- /dev/null +++ b/.github/workflows/ios-demos.yml @@ -0,0 +1,100 @@ +name: iOS Demos + +on: + workflow_dispatch: + push: + branches: [ master ] + paths: + - 'demo/ios/**' + - '.github/workflows/ios-demos.yml' + pull_request: + branches: [ master, 'v[0-9]+.[0-9]+' ] + paths: + - 'demo/ios/**' + - '.github/workflows/ios-demos.yml' + +jobs: + build-foreground-app: + runs-on: macos-latest + defaults: + run: + working-directory: demo/ios/ForegroundApp + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Node.js LTS + uses: actions/setup-node@v3 + with: + node-version: lts/* + + - name: Install Cocoapods + run: gem install cocoapods + + - name: Install AppCenter CLI + run: npm install -g appcenter-cli + + - name: Make build dir + run: mkdir ddp + + - name: Run Cocoapods + run: pod install + + - name: Build English + run: xcrun xcodebuild build + -configuration Debug + -workspace PicovoiceForegroundAppDemo.xcworkspace + -sdk iphoneos + -scheme enDemo + -derivedDataPath ddp + CODE_SIGNING_ALLOWED=NO + + - name: Build Other Language + run: xcrun xcodebuild build + -configuration Debug + -workspace PicovoiceForegroundAppDemo.xcworkspace + -sdk iphoneos + -scheme deDemo + -derivedDataPath ddp + CODE_SIGNING_ALLOWED=NO + + build-background-service: + runs-on: macos-latest + defaults: + run: + working-directory: demo/ios/BackgroundService + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Node.js LTS + uses: actions/setup-node@v3 + with: + node-version: lts/* + + - name: Install Cocoapods + run: gem install cocoapods + + - name: Install AppCenter CLI + run: npm install -g appcenter-cli + + - name: Make build dir + run: mkdir ddp + + - name: Run Cocoapods + run: pod install + + # - name: Build + # run: xcrun xcodebuild build + # -configuration Debug + # -workspace PicovoiceBackgroundServiceDemo.xcworkspace + # -sdk iphoneos + # -scheme PicovoiceBackgroundServiceDemo + # -derivedDataPath ddp + # CODE_SIGNING_ALLOWED=NO diff --git a/.github/workflows/java-demos.yml b/.github/workflows/java-demos.yml index fae48316e..232716599 100644 --- a/.github/workflows/java-demos.yml +++ b/.github/workflows/java-demos.yml @@ -20,8 +20,19 @@ defaults: working-directory: demo/java jobs: - build: - runs-on: ubuntu-latest + build-github-hosted: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + include: + - os: ubuntu-latest + platform: linux + - os: windows-latest + platform: windows + - os: macos-latest + platform: mac steps: - uses: actions/checkout@v3 @@ -37,3 +48,46 @@ jobs: - name: Build run: ./gradlew build + - name: Run filedemo + run: java -jar build/libs/picovoice-file-demo.jar + -a ${{ secrets.PV_VALID_ACCESS_KEY }} + -i ../../resources/audio_samples/picovoice-coffee.wav + -k ../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + -c ../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn + + build-self-hosted: + runs-on: ${{ matrix.machine }} + + strategy: + matrix: + machine: [rpi2, rpi3-32, rpi3-64, rpi4-32, rpi4-64, jetson, beaglebone] + include: + - machine: rpi2 + platform: raspberry-pi + - machine: rpi3-32 + platform: raspberry-pi + - machine: rpi3-64 + platform: raspberry-pi + - machine: rpi4-32 + platform: raspberry-pi + - machine: rpi4-64 + platform: raspberry-pi + - machine: jetson + platform: jetson + - machine: beaglebone + platform: beaglebone + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Build + run: ./gradlew build + + - name: Run filedemo + run: java -jar build/libs/picovoice-file-demo.jar + -a ${{ secrets.PV_VALID_ACCESS_KEY }} + -i ../../resources/audio_samples/picovoice-coffee.wav + -k ../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + -c ../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn \ No newline at end of file diff --git a/.github/workflows/nodejs-demos.yml b/.github/workflows/nodejs-demos.yml new file mode 100644 index 000000000..3de827176 --- /dev/null +++ b/.github/workflows/nodejs-demos.yml @@ -0,0 +1,100 @@ +name: Node.js Demos + +on: + workflow_dispatch: + push: + branches: [ master ] + paths: + - 'demo/nodejs/**' + - '!demo/nodejs/README.md' + - '.github/workflows/nodejs-demos.yml' + + pull_request: + branches: [ master, 'v[0-9]+.[0-9]+' ] + paths: + - 'demo/nodejs/**' + - '!demo/nodejs/README.md' + - '.github/workflows/nodejs-demos.yml' + +defaults: + run: + working-directory: demo/nodejs + +jobs: + build-github-hosted: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node-version: [14.x, 16.x, 18.x, 20.x] + include: + - os: ubuntu-latest + platform: linux + - os: windows-latest + platform: windows + - os: macos-latest + platform: mac + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Pre-build dependencies + run: npm install yarn + + - name: Install dependencies + run: yarn install + + - name: Test + run: yarn file + -a ${{ secrets.PV_VALID_ACCESS_KEY }} + -i ../../resources/audio_samples/picovoice-coffee.wav + -k ../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + -c ../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn + + build-self-hosted: + runs-on: ${{ matrix.machine }} + + strategy: + matrix: + machine: [rpi2, rpi3-32, rpi3-64, rpi4-32, rpi4-64, jetson, beaglebone] + include: + - machine: rpi2 + platform: raspberry-pi + - machine: rpi3-32 + platform: raspberry-pi + - machine: rpi3-64 + platform: raspberry-pi + - machine: rpi4-32 + platform: raspberry-pi + - machine: rpi4-64 + platform: raspberry-pi + - machine: jetson + platform: jetson + - machine: beaglebone + platform: beaglebone + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Pre-build dependencies + run: npm install --global yarn + + - name: Install dependencies + run: yarn install + + - name: Test + run: yarn file + -a ${{ secrets.PV_VALID_ACCESS_KEY }} + -i ../../resources/audio_samples/picovoice-coffee.wav + -k ../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + -c ../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn \ No newline at end of file diff --git a/.github/workflows/python-demos.yml b/.github/workflows/python-demos.yml new file mode 100644 index 000000000..447747af3 --- /dev/null +++ b/.github/workflows/python-demos.yml @@ -0,0 +1,96 @@ +name: Python Demos + +on: + workflow_dispatch: + push: + branches: [ master ] + paths: + - '.github/workflows/python-demos.yml' + - 'demo/python/**' + - '!demo/python/README.md' + pull_request: + branches: [ master, 'v[0-9]+.[0-9]+' ] + paths: + - '.github/workflows/python-demos.yml' + - 'demo/python/**' + - '!demo/python/README.md' + +defaults: + run: + working-directory: demo/python + +jobs: + build-github-hosted: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: ['3.7', '3.8', '3.9', '3.10'] + include: + - os: ubuntu-latest + platform: linux + - os: windows-latest + platform: windows + - os: macos-latest + platform: mac + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Pre-build dependencies + run: python -m pip install --upgrade pip + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Test + run: python picovoice_demo_file.py + --access_key ${{ secrets.PV_VALID_ACCESS_KEY }} + --wav_path ../../resources/audio_samples/picovoice-coffee.wav + --keyword_path ../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + --context_path ../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn + + build-self-hosted: + runs-on: ${{ matrix.machine }} + + strategy: + matrix: + machine: [rpi2, rpi3-32, rpi3-64, rpi4-32, rpi4-64, jetson, beaglebone] + include: + - machine: rpi2 + platform: raspberry-pi + - machine: rpi3-32 + platform: raspberry-pi + - machine: rpi3-64 + platform: raspberry-pi + - machine: rpi4-32 + platform: raspberry-pi + - machine: rpi4-64 + platform: raspberry-pi + - machine: jetson + platform: jetson + - machine: beaglebone + platform: beaglebone + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install dependencies + run: pip3 install -r requirements.txt + + - name: Test + run: python3 picovoice_demo_file.py + --access_key ${{ secrets.PV_VALID_ACCESS_KEY }} + --wav_path ../../resources/audio_samples/picovoice-coffee.wav + --keyword_path ../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + --context_path ../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn diff --git a/.github/workflows/rust-demos.yml b/.github/workflows/rust-demos.yml index ccded7f31..2057afd18 100644 --- a/.github/workflows/rust-demos.yml +++ b/.github/workflows/rust-demos.yml @@ -18,31 +18,98 @@ on: env: CARGO_TERM_COLOR: always +defaults: + run: + working-directory: demo/rust + jobs: - build-micdemo: - runs-on: ubuntu-latest + build-github-hosted: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + include: + - os: ubuntu-latest + platform: linux + - os: windows-latest + platform: windows + - os: macos-latest + platform: mac + steps: - uses: actions/checkout@v3 with: submodules: recursive - name: Rust dependencies - run: sudo apt update && sudo apt install -y libasound2-dev + if: matrix.os == 'ubuntu-latest' + run: sudo apt install libasound2-dev -y + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true - name: Rust build micdemo run: cargo build --verbose working-directory: demo/rust/micdemo - build-filedemo: - runs-on: ubuntu-latest + - name: Rust build filedemo + run: cargo build --verbose + working-directory: demo/rust/filedemo + + - name: Test + run: cargo run --release -- + --access_key ${{ secrets.PV_VALID_ACCESS_KEY }} + --input_audio_path ../../../resources/audio_samples/picovoice-coffee.wav + --keyword_path ../../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + --context_path ../../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn + working-directory: demo/rust/filedemo + + build-self-hosted: + runs-on: ${{ matrix.machine }} + + strategy: + matrix: + machine: [rpi3-32, rpi3-64, rpi4-32, rpi4-64, jetson] + include: + - machine: rpi3-32 + platform: raspberry-pi + - machine: rpi3-64 + platform: raspberry-pi + - machine: rpi4-32 + platform: raspberry-pi + - machine: rpi4-64 + platform: raspberry-pi + - machine: jetson + platform: jetson + steps: - uses: actions/checkout@v3 with: submodules: recursive - - name: Rust dependencies - run: sudo apt update && sudo apt install -y libasound2-dev + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + + - name: Rust build micdemo + run: cargo build --verbose + working-directory: demo/rust/micdemo - name: Rust build filedemo run: cargo build --verbose working-directory: demo/rust/filedemo + + - name: Test + run: cargo run --release -- + --access_key ${{ secrets.PV_VALID_ACCESS_KEY }} + --input_audio_path ../../../resources/audio_samples/picovoice-coffee.wav + --keyword_path ../../../resources/porcupine/resources/keyword_files/${{ matrix.platform }}/picovoice_${{ matrix.platform }}.ppn + --context_path ../../../resources/rhino/resources/contexts/${{ matrix.platform }}/coffee_maker_${{ matrix.platform }}.rhn + working-directory: demo/rust/filedemo \ No newline at end of file diff --git a/.github/workflows/web-demos.yml b/.github/workflows/web-demos.yml new file mode 100644 index 000000000..7b1fa8ca8 --- /dev/null +++ b/.github/workflows/web-demos.yml @@ -0,0 +1,44 @@ +name: Web Demos + +on: + workflow_dispatch: + push: + branches: [ master ] + paths: + - 'demo/web/**' + - '!demo/web/README.md' + - '.github/workflows/web-demos.yml' + pull_request: + branches: [ master, 'v[0-9]+.[0-9]+' ] + paths: + - 'demo/web/**' + - '!demo/web/README.md' + - '.github/workflows/web-demos.yml' + +defaults: + run: + working-directory: demo/web + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x, 16.x, 18.x, 20.x] + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Pre-build dependencies + run: npm install yarn + + - name: Install dependencies + run: yarn install diff --git a/demo/c/picovoice_demo_file.c b/demo/c/picovoice_demo_file.c index 252ccf1ce..b35a75ff2 100644 --- a/demo/c/picovoice_demo_file.c +++ b/demo/c/picovoice_demo_file.c @@ -19,7 +19,7 @@ #include #define UTF8_COMPOSITION_FLAG (0) -#define NULL_TERMINATED (-1) +#define NULL_TERMINATED (-1) #else @@ -44,7 +44,6 @@ static void *open_dl(const char *dl_path) { return dlopen(dl_path, RTLD_NOW); #endif - } static void *load_symbol(void *handle, const char *symbol) { @@ -58,7 +57,6 @@ static void *load_symbol(void *handle, const char *symbol) { return dlsym(handle, symbol); #endif - } static void close_dl(void *handle) { @@ -72,7 +70,6 @@ static void close_dl(void *handle) { dlclose(handle); #endif - } static void print_dl_error(const char *message) { @@ -86,7 +83,6 @@ static void print_dl_error(const char *message) { fprintf(stderr, "%s with '%s'.\n", message, dlerror()); #endif - } static void wake_word_callback(void) { @@ -241,7 +237,7 @@ int picovoice_main(int argc, char *argv[]) { } pv_status_t (*pv_picovoice_process_func)(pv_picovoice_t *, const int16_t *) = - load_symbol(picovoice_library, "pv_picovoice_process"); + load_symbol(picovoice_library, "pv_picovoice_process"); if (!pv_picovoice_process_func) { print_dl_error("failed to load 'pv_picovoice_process'"); exit(1); diff --git a/demo/c/picovoice_demo_mic.c b/demo/c/picovoice_demo_mic.c index 11216c103..dcbd06cbb 100644 --- a/demo/c/picovoice_demo_mic.c +++ b/demo/c/picovoice_demo_mic.c @@ -42,7 +42,6 @@ static void *open_dl(const char *dl_path) { return dlopen(dl_path, RTLD_NOW); #endif - } static void *load_symbol(void *handle, const char *symbol) { @@ -56,7 +55,6 @@ static void *load_symbol(void *handle, const char *symbol) { return dlsym(handle, symbol); #endif - } static void close_dl(void *handle) { @@ -70,7 +68,6 @@ static void close_dl(void *handle) { dlclose(handle); #endif - } static void print_dl_error(const char *message) { @@ -84,7 +81,6 @@ static void print_dl_error(const char *message) { fprintf(stderr, "%s with '%s'.\n", message, dlerror()); #endif - } static struct option long_options[] = { @@ -271,7 +267,7 @@ int picovoice_main(int argc, char *argv[]) { } pv_status_t (*pv_picovoice_process_func)(pv_picovoice_t *, const int16_t *) = - load_symbol(picovoice_library, "pv_picovoice_process"); + load_symbol(picovoice_library, "pv_picovoice_process"); if (!pv_picovoice_process_func) { print_dl_error("failed to load 'pv_picovoice_process'"); exit(1); @@ -358,8 +354,7 @@ int picovoice_main(int argc, char *argv[]) { status = pv_picovoice_process_func(picovoice, pcm); if (status != PV_STATUS_SUCCESS) { - fprintf(stderr, "'pv_picovoice_process' failed with '%s'\n", - pv_status_to_string_func(status)); + fprintf(stderr, "'pv_picovoice_process' failed with '%s'\n", pv_status_to_string_func(status)); exit(1); } } @@ -386,14 +381,14 @@ int main(int argc, char *argv[]) { #if defined(_WIN32) || defined(_WIN64) #define UTF8_COMPOSITION_FLAG (0) -#define NULL_TERMINATED (-1) +#define NULL_TERMINATED (-1) LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &argc); if (wargv == NULL) { fprintf(stderr, "CommandLineToArgvW failed\n"); exit(1); } - + char *utf8_argv[argc]; for (int i = 0; i < argc; ++i) { diff --git a/demo/mcu/stm32f407/stm32f407g-disc1/Src/main.c b/demo/mcu/stm32f407/stm32f407g-disc1/Src/main.c index 60724c276..971661c53 100644 --- a/demo/mcu/stm32f407/stm32f407g-disc1/Src/main.c +++ b/demo/mcu/stm32f407/stm32f407g-disc1/Src/main.c @@ -23,7 +23,7 @@ #define MEMORY_BUFFER_SIZE (70 * 1024) -static const char* ACCESS_KEY = "${ACCESS_KEY}"; //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/) +static const char *ACCESS_KEY = "${ACCESS_KEY}"; //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/) static int8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16))); @@ -38,7 +38,7 @@ static void wake_word_callback(void) { } static void inference_callback(pv_inference_t *inference) { - BSP_LED_Off(LED4); + BSP_LED_Off(LED4); printf("{\n"); printf(" is_understood : '%s',\n", (inference->is_understood ? "true" : "false")); if (inference->is_understood) { @@ -53,17 +53,18 @@ static void inference_callback(pv_inference_t *inference) { } printf("}\n\n"); for (int32_t i = 0; i < 10; i++) { - BSP_LED_Toggle(LED3); - BSP_LED_Toggle(LED4); - BSP_LED_Toggle(LED5); - BSP_LED_Toggle(LED6); - HAL_Delay(30); + BSP_LED_Toggle(LED3); + BSP_LED_Toggle(LED4); + BSP_LED_Toggle(LED5); + BSP_LED_Toggle(LED6); + HAL_Delay(30); } pv_inference_delete(inference); } static void error_handler(void) { - while(true); + while (true) + ; } int main(void) { @@ -131,7 +132,6 @@ int main(void) { error_handler(); } } - } pv_board_deinit(); pv_audio_rec_deinit(); diff --git a/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_audio_rec.c b/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_audio_rec.c index a7fce4c05..2d2baee0a 100644 --- a/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_audio_rec.c +++ b/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_audio_rec.c @@ -17,13 +17,13 @@ #include "picovoice.h" -#define PV_AUDIO_REC_AUDIO_FREQUENCY (16000U) -#define PV_AUDIO_REC_CHANNEL_NUMBER (1) +#define PV_AUDIO_REC_AUDIO_FREQUENCY (16000U) +#define PV_AUDIO_REC_CHANNEL_NUMBER (1) #define PV_AUDIO_REC_RECORD_BUFFER_SIZE (512) -#define PV_AUDIO_REC_VOLUME_LEVEL (100) +#define PV_AUDIO_REC_VOLUME_LEVEL (100) -#define AUDIO_IN_PCM_BUFFER_SIZE ((uint32_t)(PV_AUDIO_REC_AUDIO_FREQUENCY / 1000 * PV_AUDIO_REC_CHANNEL_NUMBER)) -#define AUDIO_IN_PDM_BUFFER_SIZE ((uint32_t)(128 * PV_AUDIO_REC_AUDIO_FREQUENCY / 16000 * PV_AUDIO_REC_CHANNEL_NUMBER)) +#define AUDIO_IN_PCM_BUFFER_SIZE ((uint32_t) (PV_AUDIO_REC_AUDIO_FREQUENCY / 1000 * PV_AUDIO_REC_CHANNEL_NUMBER)) +#define AUDIO_IN_PDM_BUFFER_SIZE ((uint32_t) (128 * PV_AUDIO_REC_AUDIO_FREQUENCY / 16000 * PV_AUDIO_REC_CHANNEL_NUMBER)) static uint16_t record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE]; static uint16_t record_pcm_buffer[2 * AUDIO_IN_PCM_BUFFER_SIZE]; @@ -58,7 +58,7 @@ pv_status_t pv_audio_rec_init(void) { } pv_status_t pv_audio_rec_start(void) { - if (BSP_AUDIO_IN_Record((uint16_t*)(record_pdm_buffer), AUDIO_IN_PDM_BUFFER_SIZE) != AUDIO_OK) { + if (BSP_AUDIO_IN_Record((uint16_t *) (record_pdm_buffer), AUDIO_IN_PDM_BUFFER_SIZE) != AUDIO_OK) { return PV_STATUS_INVALID_STATE; } pv_audio_rec.is_recording = true; @@ -80,8 +80,8 @@ const int16_t *pv_audio_rec_get_new_buffer(void) { } void BSP_AUDIO_IN_TransferComplete_CallBack(void) { - BSP_AUDIO_IN_PDMToPCM((uint16_t*) &record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE / 2], - record_pcm_buffer); + BSP_AUDIO_IN_PDMToPCM((uint16_t *) &record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE / 2], + record_pcm_buffer); for (uint32_t i = 0; i < AUDIO_IN_PCM_BUFFER_SIZE; i++) { ping_pong_buffer[write_index][buffer_index++] = record_pcm_buffer[i * 2]; } @@ -93,8 +93,8 @@ void BSP_AUDIO_IN_TransferComplete_CallBack(void) { } void BSP_AUDIO_IN_HalfTransfer_CallBack(void) { - BSP_AUDIO_IN_PDMToPCM((uint16_t*) &record_pdm_buffer[0], - record_pcm_buffer); + BSP_AUDIO_IN_PDMToPCM((uint16_t *) &record_pdm_buffer[0], + record_pcm_buffer); for (uint32_t i = 0; i < AUDIO_IN_PCM_BUFFER_SIZE; i++) { ping_pong_buffer[write_index][buffer_index++] = record_pcm_buffer[i * 2]; } diff --git a/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_st_f407.c b/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_st_f407.c index 120e6b966..e25faa96b 100644 --- a/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_st_f407.c +++ b/demo/mcu/stm32f407/stm32f407g-disc1/Src/pv_st_f407.c @@ -17,7 +17,7 @@ #include "pv_st_f407.h" #define UUID_ADDRESS (0x1FFF7A10) -#define UUID_SIZE (12) +#define UUID_SIZE (12) static uint8_t uuid[UUID_SIZE]; @@ -34,7 +34,7 @@ static pv_status_t pv_clock_config(void) { RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 7; - if ( HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { return PV_STATUS_INVALID_STATE; } RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); @@ -42,11 +42,10 @@ static pv_status_t pv_clock_config(void) { RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - if ( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { - return PV_STATUS_INVALID_STATE; - } - if (HAL_GetREVID() == 0x1001) - { + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { + return PV_STATUS_INVALID_STATE; + } + if (HAL_GetREVID() == 0x1001) { __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); } return PV_STATUS_SUCCESS; @@ -82,11 +81,11 @@ void pv_board_deinit() { void pv_error_handler(void) { __disable_irq(); - while(true); + while (true) + ; } -void assert_failed(uint8_t* file, uint32_t line) -{ +void assert_failed(uint8_t *file, uint32_t line) { (void) file; (void) line; pv_error_handler(); diff --git a/demo/mcu/stm32f411/stm32f411e-disco/Src/main.c b/demo/mcu/stm32f411/stm32f411e-disco/Src/main.c index 84262cc98..36c55f590 100644 --- a/demo/mcu/stm32f411/stm32f411e-disco/Src/main.c +++ b/demo/mcu/stm32f411/stm32f411e-disco/Src/main.c @@ -23,7 +23,7 @@ #define MEMORY_BUFFER_SIZE (70 * 1024) -static const char* ACCESS_KEY = "${ACCESS_KEY}"; //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/) +static const char *ACCESS_KEY = "${ACCESS_KEY}"; //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/) static int8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16))); @@ -63,7 +63,8 @@ static void inference_callback(pv_inference_t *inference) { } static void error_handler(void) { - while(true); + while (true) + ; } int main(void) { @@ -132,7 +133,6 @@ int main(void) { error_handler(); } } - } pv_board_deinit(); pv_audio_rec_deinit(); diff --git a/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_audio_rec.c b/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_audio_rec.c index cb3b11f2b..df6fd809b 100644 --- a/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_audio_rec.c +++ b/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_audio_rec.c @@ -17,13 +17,13 @@ #include "picovoice.h" -#define PV_AUDIO_REC_AUDIO_FREQUENCY (16000U) -#define PV_AUDIO_REC_CHANNEL_NUMBER (1) +#define PV_AUDIO_REC_AUDIO_FREQUENCY (16000U) +#define PV_AUDIO_REC_CHANNEL_NUMBER (1) #define PV_AUDIO_REC_RECORD_BUFFER_SIZE (512) -#define PV_AUDIO_REC_VOLUME_LEVEL (100) +#define PV_AUDIO_REC_VOLUME_LEVEL (100) -#define AUDIO_IN_PCM_BUFFER_SIZE ((uint32_t)(PV_AUDIO_REC_AUDIO_FREQUENCY / 1000 * PV_AUDIO_REC_CHANNEL_NUMBER)) -#define AUDIO_IN_PDM_BUFFER_SIZE ((uint32_t)(128 * PV_AUDIO_REC_AUDIO_FREQUENCY / 16000 * PV_AUDIO_REC_CHANNEL_NUMBER)) +#define AUDIO_IN_PCM_BUFFER_SIZE ((uint32_t) (PV_AUDIO_REC_AUDIO_FREQUENCY / 1000 * PV_AUDIO_REC_CHANNEL_NUMBER)) +#define AUDIO_IN_PDM_BUFFER_SIZE ((uint32_t) (128 * PV_AUDIO_REC_AUDIO_FREQUENCY / 16000 * PV_AUDIO_REC_CHANNEL_NUMBER)) static uint16_t record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE]; static uint16_t record_pcm_buffer[2 * AUDIO_IN_PCM_BUFFER_SIZE]; @@ -58,7 +58,7 @@ pv_status_t pv_audio_rec_init(void) { } pv_status_t pv_audio_rec_start(void) { - if (BSP_AUDIO_IN_Record((uint16_t*)(record_pdm_buffer), AUDIO_IN_PDM_BUFFER_SIZE) != AUDIO_OK) { + if (BSP_AUDIO_IN_Record((uint16_t *) (record_pdm_buffer), AUDIO_IN_PDM_BUFFER_SIZE) != AUDIO_OK) { return PV_STATUS_INVALID_STATE; } pv_audio_rec.is_recording = true; @@ -80,8 +80,8 @@ const int16_t *pv_audio_rec_get_new_buffer(void) { } void BSP_AUDIO_IN_TransferComplete_CallBack(void) { - BSP_AUDIO_IN_PDMToPCM((uint16_t*) &record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE / 2], - record_pcm_buffer); + BSP_AUDIO_IN_PDMToPCM((uint16_t *) &record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE / 2], + record_pcm_buffer); for (uint32_t i = 0; i < AUDIO_IN_PCM_BUFFER_SIZE; i++) { ping_pong_buffer[write_index][buffer_index++] = record_pcm_buffer[i * 2]; } @@ -93,8 +93,8 @@ void BSP_AUDIO_IN_TransferComplete_CallBack(void) { } void BSP_AUDIO_IN_HalfTransfer_CallBack(void) { - BSP_AUDIO_IN_PDMToPCM((uint16_t*) &record_pdm_buffer[0], - record_pcm_buffer); + BSP_AUDIO_IN_PDMToPCM((uint16_t *) &record_pdm_buffer[0], + record_pcm_buffer); for (uint32_t i = 0; i < AUDIO_IN_PCM_BUFFER_SIZE; i++) { ping_pong_buffer[write_index][buffer_index++] = record_pcm_buffer[i * 2]; } diff --git a/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_st_f411.c b/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_st_f411.c index f77fd3bed..782ffcb12 100644 --- a/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_st_f411.c +++ b/demo/mcu/stm32f411/stm32f411e-disco/Src/pv_st_f411.c @@ -17,7 +17,7 @@ #include "pv_st_f411.h" #define UUID_ADDRESS (0x1FFF7A10) -#define UUID_SIZE (12) +#define UUID_SIZE (12) static uint8_t uuid[UUID_SIZE]; @@ -35,7 +35,7 @@ static pv_status_t pv_clock_config(void) { RCC_OscInitStruct.PLL.PLLN = 400; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; RCC_OscInitStruct.PLL.PLLQ = 7; - if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { return PV_STATUS_INVALID_STATE; } RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); @@ -43,7 +43,7 @@ static pv_status_t pv_clock_config(void) { RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) { + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) { return PV_STATUS_INVALID_STATE; } return PV_STATUS_SUCCESS; @@ -79,11 +79,11 @@ void pv_board_deinit() { void pv_error_handler(void) { __disable_irq(); - while(true); + while (true) + ; } -void assert_failed(uint8_t* file, uint32_t line) -{ +void assert_failed(uint8_t *file, uint32_t line) { (void) file; (void) line; pv_error_handler(); diff --git a/demo/mcu/stm32f769/stm32f769i-disco/Src/main.c b/demo/mcu/stm32f769/stm32f769i-disco/Src/main.c index e21d4f0f2..0ce2b5c1a 100644 --- a/demo/mcu/stm32f769/stm32f769i-disco/Src/main.c +++ b/demo/mcu/stm32f769/stm32f769i-disco/Src/main.c @@ -23,7 +23,7 @@ #define MEMORY_BUFFER_SIZE (70 * 1024) -static const char* ACCESS_KEY = "${ACCESS_KEY}"; //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/) +static const char *ACCESS_KEY = "${ACCESS_KEY}"; //AccessKey string obtained from Picovoice Console (https://picovoice.ai/console/) static int8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16))); @@ -61,7 +61,8 @@ static void inference_callback(pv_inference_t *inference) { } static void error_handler(void) { - while(true); + while (true) + ; } int main(void) { @@ -135,7 +136,6 @@ int main(void) { error_handler(); } } - } pv_board_deinit(); pv_audio_rec_deinit(); diff --git a/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_audio_rec.c b/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_audio_rec.c index 5c8034ee0..7fb356d33 100644 --- a/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_audio_rec.c +++ b/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_audio_rec.c @@ -20,22 +20,22 @@ #define PV_INT16_MAX (32767) #define PV_INT16_MIN (-32767 - 1) -#define pv_int32_to_int16(N) (((N)<(PV_INT16_MIN))?(PV_INT16_MIN):(((N)>(PV_INT16_MAX))?(PV_INT16_MAX):(N))) +#define pv_int32_to_int16(N) (((N) < (PV_INT16_MIN)) ? (PV_INT16_MIN) : (((N) > (PV_INT16_MAX)) ? (PV_INT16_MAX) : (N))) __IO uint32_t SdmmcTest = 0; __IO uint32_t SdramTest = 0; -#define PV_AUDIO_REC_AUDIO_FREQUENCY (16000U) -#define PV_AUDIO_REC_CHANNEL_NUMBER (2) +#define PV_AUDIO_REC_AUDIO_FREQUENCY (16000U) +#define PV_AUDIO_REC_CHANNEL_NUMBER (2) #define PV_AUDIO_REC_RECORD_BUFFER_SIZE (512) -#define PV_AUDIO_REC_VOLUME_LEVEL (100) +#define PV_AUDIO_REC_VOLUME_LEVEL (100) -#define AUDIO_IN_PCM_BUFFER_SIZE (PV_AUDIO_REC_RECORD_BUFFER_SIZE) -#define AUDIO_IN_PDM_BUFFER_SIZE (AUDIO_IN_PCM_BUFFER_SIZE / 4) +#define AUDIO_IN_PCM_BUFFER_SIZE (PV_AUDIO_REC_RECORD_BUFFER_SIZE) +#define AUDIO_IN_PDM_BUFFER_SIZE (AUDIO_IN_PCM_BUFFER_SIZE / 4) -ALIGN_32BYTES (static int32_t record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE]); -ALIGN_32BYTES (static uint16_t record_pcm_buffer[AUDIO_IN_PCM_BUFFER_SIZE]); -ALIGN_32BYTES (static int16_t ping_pong_buffer[2][PV_AUDIO_REC_RECORD_BUFFER_SIZE]); +ALIGN_32BYTES(static int32_t record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE]); +ALIGN_32BYTES(static uint16_t record_pcm_buffer[AUDIO_IN_PCM_BUFFER_SIZE]); +ALIGN_32BYTES(static int16_t ping_pong_buffer[2][PV_AUDIO_REC_RECORD_BUFFER_SIZE]); static int32_t last_read_index = -1; static int32_t read_index = 1; @@ -67,7 +67,7 @@ pv_status_t pv_audio_rec_init(void) { pv_status_t pv_audio_rec_start(void) { pv_audio_rec_init(); - if (BSP_AUDIO_IN_Record((uint16_t*)(record_pcm_buffer), AUDIO_IN_PCM_BUFFER_SIZE) != AUDIO_OK) { + if (BSP_AUDIO_IN_Record((uint16_t *) (record_pcm_buffer), AUDIO_IN_PCM_BUFFER_SIZE) != AUDIO_OK) { return PV_STATUS_INVALID_STATE; } pv_audio_rec.is_recording = true; @@ -99,7 +99,7 @@ const int16_t *pv_audio_rec_get_new_buffer(void) { static inline int16_t pv_hpf(int16_t s_int16, int16_t s_old_int16) { //0xFC and 0x100 are the tuning parameters come from st for high pass filter pv_audio_rec.filter_old_output = (0xFC * (pv_audio_rec.filter_old_output + (int32_t) s_int16 - (int32_t) s_old_int16)) / 0x100; - return (int16_t)pv_int32_to_int16(pv_audio_rec.filter_old_output); + return (int16_t) pv_int32_to_int16(pv_audio_rec.filter_old_output); } void BSP_AUDIO_IN_TransferComplete_CallBack(void) { @@ -108,7 +108,7 @@ void BSP_AUDIO_IN_TransferComplete_CallBack(void) { record_pcm_buffer[(AUDIO_IN_PCM_BUFFER_SIZE / 2) + i * 2], record_pcm_buffer[(AUDIO_IN_PCM_BUFFER_SIZE / 2) + (i - 1) * 2]); } - + if (buffer_index >= AUDIO_IN_PCM_BUFFER_SIZE) { read_index = write_index; write_index = 1 - write_index; @@ -117,7 +117,7 @@ void BSP_AUDIO_IN_TransferComplete_CallBack(void) { } void BSP_AUDIO_IN_HalfTransfer_CallBack(void) { - ping_pong_buffer[write_index][buffer_index++] = pv_hpf(record_pcm_buffer[0], record_pcm_buffer[AUDIO_IN_PCM_BUFFER_SIZE-2]); + ping_pong_buffer[write_index][buffer_index++] = pv_hpf(record_pcm_buffer[0], record_pcm_buffer[AUDIO_IN_PCM_BUFFER_SIZE - 2]); for (uint32_t i = 1; i < AUDIO_IN_PCM_BUFFER_SIZE / 4; i++) { ping_pong_buffer[write_index][buffer_index++] = pv_hpf( record_pcm_buffer[i * 2], @@ -131,7 +131,8 @@ void BSP_AUDIO_IN_HalfTransfer_CallBack(void) { } void BSP_AUDIO_IN_Error_CallBack(void) { - while (1); + while (1) + ; } void pv_audio_rec_deinit(void) { diff --git a/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_st_f769.c b/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_st_f769.c index 7a8d30e2e..b09957076 100644 --- a/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_st_f769.c +++ b/demo/mcu/stm32f769/stm32f769i-disco/Src/pv_st_f769.c @@ -16,51 +16,51 @@ #include "pv_st_f769.h" -#define UUID_ADDRESS (0x1FF0F420) -#define UUID_SIZE (12) +#define UUID_ADDRESS (0x1FF0F420) +#define UUID_SIZE (12) -#define PV_COM (USART1) -#define PV_COM_ALT (GPIO_AF7_USART1) -#define PV_COM_IRQn (USART1_IRQn) -#define PV_COM_TX_Pin (GPIO_PIN_10) -#define PV_COM_TX_GPIO_Port (GPIOA) -#define PV_COM_RX_Pin (GPIO_PIN_9) -#define PV_COM_RX_GPIO_Port (GPIOA) +#define PV_COM (USART1) +#define PV_COM_ALT (GPIO_AF7_USART1) +#define PV_COM_IRQn (USART1_IRQn) +#define PV_COM_TX_Pin (GPIO_PIN_10) +#define PV_COM_TX_GPIO_Port (GPIOA) +#define PV_COM_RX_Pin (GPIO_PIN_9) +#define PV_COM_RX_GPIO_Port (GPIOA) static uint8_t uuid[UUID_SIZE]; UART_HandleTypeDef huart; static pv_status_t pv_clock_config(void) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_OscInitTypeDef RCC_OscInitStruct; - HAL_StatusTypeDef ret = HAL_OK; - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 25; - RCC_OscInitStruct.PLL.PLLN = 400; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 8; - RCC_OscInitStruct.PLL.PLLR = 7; - ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); - if(ret != HAL_OK) { - return PV_STATUS_INVALID_STATE; - } - ret = HAL_PWREx_EnableOverDrive(); - if(ret != HAL_OK) { - return PV_STATUS_INVALID_STATE; - } - RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6); - if(ret != HAL_OK) { - return PV_STATUS_INVALID_STATE; - } + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; + HAL_StatusTypeDef ret = HAL_OK; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 25; + RCC_OscInitStruct.PLL.PLLN = 400; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 8; + RCC_OscInitStruct.PLL.PLLR = 7; + ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); + if (ret != HAL_OK) { + return PV_STATUS_INVALID_STATE; + } + ret = HAL_PWREx_EnableOverDrive(); + if (ret != HAL_OK) { + return PV_STATUS_INVALID_STATE; + } + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6); + if (ret != HAL_OK) { + return PV_STATUS_INVALID_STATE; + } return PV_STATUS_SUCCESS; } @@ -108,8 +108,8 @@ const uint32_t pv_get_uuid_size(void) { } pv_status_t pv_board_init() { - SCB_EnableICache(); - SCB_EnableDCache(); + SCB_EnableICache(); + SCB_EnableDCache(); if (HAL_Init() != HAL_OK) { return PV_STATUS_INVALID_STATE; } @@ -128,17 +128,17 @@ void pv_board_deinit() { } void pv_error_handler(void) { - while(true); + while (true) + ; } -void assert_failed(uint8_t* file, uint32_t line) -{ +void assert_failed(uint8_t *file, uint32_t line) { (void) file; (void) line; pv_error_handler(); } -int __io_putchar (int ch) { +int __io_putchar(int ch) { HAL_UART_Transmit(&huart, (uint8_t *) &ch, 1, 1000); return ch; } diff --git a/demo/respeaker-rpi0/picovoice_demo_mic.c b/demo/respeaker-rpi0/picovoice_demo_mic.c index 2a91a1fd3..78023b784 100644 --- a/demo/respeaker-rpi0/picovoice_demo_mic.c +++ b/demo/respeaker-rpi0/picovoice_demo_mic.c @@ -9,15 +9,15 @@ specific language governing permissions and limitations under the License. */ +#include +#include #include #include #include +#include #include #include #include -#include -#include -#include #include #include "pv_picovoice.h" @@ -73,8 +73,8 @@ static void spi_write_data(unsigned char *data, int len) { struct spi_ioc_transfer spi; memset(&spi, 0, sizeof(spi)); - spi.tx_buf = (unsigned long)data; - spi.rx_buf = (unsigned long)data; + spi.tx_buf = (unsigned long) data; + spi.rx_buf = (unsigned long) data; spi.len = len; spi.delay_usecs = spi_delay; spi.speed_hz = spi_speed; @@ -87,13 +87,13 @@ static void spi_write_data(unsigned char *data, int len) { } static void set_color(const uint8_t rgb[3]) { - for(int32_t i = 0; i < 4; i++) { + for (int32_t i = 0; i < 4; i++) { uint8_t zero = 0x00; spi_write_data(&zero, 1); } static const uint32_t BRIGHTNESS = 1; - for(int32_t i = 0; i < 12; i++) { + for (int32_t i = 0; i < 12; i++) { uint8_t led_frame[4]; led_frame[0] = 0b11100000 | (0b00011111 & BRIGHTNESS); led_frame[1] = rgb[2]; @@ -102,7 +102,7 @@ static void set_color(const uint8_t rgb[3]) { spi_write_data(led_frame, 4); } - for(int32_t i = 0; i < 4; i++) { + for (int32_t i = 0; i < 4; i++) { uint8_t zero = 0x00; spi_write_data(&zero, 1); } @@ -175,15 +175,16 @@ static struct option long_options[] = { {"porcupine_model_path", required_argument, NULL, 'p'}, {"rhino_sensitivity", required_argument, NULL, 't'}, {"rhino_model_path", required_argument, NULL, 'r'}, - {"require_endpoint", required_argument, NULL, 'e'}, - {"input_audio_device", required_argument, NULL, 'i'} + {"require_endpoint", required_argument, NULL, 'e'}, + {"input_audio_device", required_argument, NULL, 'i'} }; void print_usage(const char *program_name) { fprintf(stderr, "Usage : %s -l LIBRARY_PATH -a ACCESS_KEY -k KEYWORD_PATH -c CONTEXT_PATH -p PPN_MODEL_PATH -r RHN_MODEL_PATH -i INPUT_AUDIO_DEVICE " "[--porcupine_sensitivity PPN_SENSITIVITY --rhino_sensitivity RHN_SENSITIVITY --require_endpoint \"true\"|\"false\" ]\n", - program_name, program_name); + program_name, + program_name); } int main(int argc, char *argv[]) { @@ -293,7 +294,7 @@ int main(int argc, char *argv[]) { } pv_status_t (*pv_picovoice_process_func)(pv_picovoice_t *, const int16_t *) = - dlsym(picovoice_library, "pv_picovoice_process"); + dlsym(picovoice_library, "pv_picovoice_process"); if ((error = dlerror()) != NULL) { fprintf(stderr, "failed to load 'pv_picovoice_process' with '%s'", error); exit(1); diff --git a/resources/.lint/c/formatter.py b/resources/.lint/c/formatter.py new file mode 100644 index 000000000..e08048680 --- /dev/null +++ b/resources/.lint/c/formatter.py @@ -0,0 +1,83 @@ +import fnmatch +import os +import re +import subprocess +from argparse import ArgumentParser + +import sys + +IGNORE_LIST = { + 'demo/c/dr_libs', + 'demo/c/pvrecorder', + 'resources/porcupine', + 'resources/rhino', + 'lib' +} + +EXCLUDE_PATTERN = { + '.*ios.*', + '.*node_modules.*', + '.*?/mcu(?!.*src/(pv|main)).*', + '.*build.*', +} + + +def main(): + parser = ArgumentParser() + + parser.add_argument('--verbose', + '-v', + action='store_true', + help='If set, shows the list of processed files') + parser.add_argument('--check-only', + '-c', + action='store_true', + help='If set, checks for warnings only') + + input_args = parser.parse_args() + formatter(input_args.verbose, input_args.check_only) + + +def formatter(verbose, check_only): + if check_only: + cmd = "clang-format --dry-run --Werror --verbose" + else: + cmd = "clang-format -i -style=file --verbose" + print(cmd) + + src_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../../../') + all_files = find('*.c', src_dir) + all_files.extend(find('*.h', src_dir)) + + c_source_files = [file_path for file_path in all_files if + not any(ignored_path in file_path for ignored_path in IGNORE_LIST)] + + c_source_files = [file_path for file_path in c_source_files if + not any(re.match(pattern, file_path, flags=re.IGNORECASE) for pattern in EXCLUDE_PATTERN)] + + c_source_files_num = len(c_source_files) + for index, c_source_file in enumerate(c_source_files): + format_command = f"{cmd} {c_source_file}" + try: + result = subprocess.check_output(format_command, shell=True, stderr=subprocess.STDOUT).decode('utf-8') + except subprocess.CalledProcessError as e: + print(f'Formatter failed with ({e.returncode}):\n{e.output.decode("utf-8")}') + continue + + if verbose: + print(result) + sys.stdout.write(f"Completion: {index / c_source_files_num * 100:.2f}%\r") + sys.stdout.flush() + + +def find(pattern, path): + file_list = [] + for root, dirs, files in os.walk(path): + for name in files: + if fnmatch.fnmatch(name, pattern): + file_list.append(os.path.join(root, name)) + return file_list + + +if __name__ == '__main__': + main() diff --git a/sdk/c/include/picovoice.h b/sdk/c/include/picovoice.h index 147f6beec..3631832a9 100644 --- a/sdk/c/include/picovoice.h +++ b/sdk/c/include/picovoice.h @@ -54,7 +54,6 @@ typedef enum { PV_API const char *pv_status_to_string(pv_status_t status); #ifdef __cplusplus - } #endif diff --git a/sdk/c/include/pv_picovoice.h b/sdk/c/include/pv_picovoice.h index 1b814c5fa..5791b7b71 100644 --- a/sdk/c/include/pv_picovoice.h +++ b/sdk/c/include/pv_picovoice.h @@ -148,7 +148,6 @@ PV_API int32_t pv_picovoice_frame_length(void); PV_API pv_status_t pv_picovoice_context_info(const pv_picovoice_t *object, const char **context); #ifdef __cplusplus - } #endif