Skip to content

Commit

Permalink
Merge pull request #83 from xmos/feature/amz_updates
Browse files Browse the repository at this point in the history
Refactor CLI arguments of scripts and other changes
  • Loading branch information
xluciano authored Jul 6, 2022
2 parents e9bc421 + c0d2ed7 commit ccd8e71
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 116 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ Feature enhancements, updates, and resolved issues from all releases are availab

**XMOS-only change** - version 0:

* refactor CLI arguments in setup scripts in order to support Amazon KWD
* port XMOS KWD adapters to latest version of the SDK
* delay startup of AVS console till .asoundrc file is found
* clone portaudio from github instead of using wget as it is more reliable

### Version 1.25.0 - August 23 2021
Feature enhancements, updates, and resolved issues from all releases are available on the [Amazon developer portal](https://developer.amazon.com/docs/alexa/avs-device-sdk/release-notes.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ static std::shared_ptr<acsdkKWDImplementations::AbstractKeywordDetector> createA
std::shared_ptr<acsdkKWDInterfaces::KeywordNotifierInterface> keywordNotifier,
std::shared_ptr<acsdkKWDInterfaces::KeywordDetectorStateNotifierInterface> keywordDetectorStateNotifier) {
std::string modelFilePath;
#ifdef SENSORY_OP_POINT
uint32_t operatingPoint = 0;
#endif // SENSORY_OP_POINT

auto config = avsCommon::utils::configuration::ConfigurationNode::getRoot()[SAMPLE_APP_CONFIG_ROOT_KEY]
[SENSORY_CONFIG_ROOT_KEY];
if (config) {
config.getString(SENSORY_MODEL_FILE_PATH, &modelFilePath);
#ifdef SENSORY_OP_POINT
uint32_t operatingPoint = 0;
config.getUint32(SENSORY_SNSR_OPERATING_POINT, &operatingPoint);
SensoryKeywordDetector::setSnsrOperatingPoint(operatingPoint);
#endif // SENSORY_OP_POINT
Expand All @@ -61,7 +64,7 @@ static std::shared_ptr<acsdkKWDImplementations::AbstractKeywordDetector> createA
return nullptr;
}
#ifdef SENSORY_OP_POINT
if (m_snsrOperatingPoint==0) {
if (operatingPoint==0) {
ACSDK_ERROR(LX("createFailed").d("reason", "zeroSnsrOperatingPoint"));
return nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SensoryKeywordDetector : public acsdkKWDImplementations::AbstractKeywordDe
*/
~SensoryKeywordDetector() override;

#ifdef SENSORY_OP_POINT
/**
* Set the operating point of the SNSR engine.
*
Expand All @@ -105,6 +106,7 @@ class SensoryKeywordDetector : public acsdkKWDImplementations::AbstractKeywordDe
static void setSnsrOperatingPoint(int value) {
m_snsrOperatingPoint = value;
};
#endif // SENSORY_OP_POINT

private:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ static const avsCommon::utils::AudioFormat::Encoding SENSORY_COMPATIBLE_ENCODING
static const avsCommon::utils::AudioFormat::Endianness SENSORY_COMPATIBLE_ENDIANNESS =
avsCommon::utils::AudioFormat::Endianness::LITTLE;

#ifdef SENSORY_OP_POINT
uint32_t SensoryKeywordDetector::m_snsrOperatingPoint = 0;
#endif // SENSORY_OP_POINT

/**
* Checks to see if an @c avsCommon::utils::AudioFormat is compatible with Sensory.
*
Expand Down Expand Up @@ -353,7 +357,7 @@ bool SensoryKeywordDetector::setUpRuntimeSettings(SnsrSession* session) {
return false;
}
ACSDK_INFO(LX("setUpRuntimeSettings")
.d("operating point",op));
.d("operating point", op));
#endif // SENSORY_OP_POINT
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,6 @@ class XMOSKeywordDetector : public acsdkKWDImplementations::AbstractKeywordDetec

public:

/**
* Creates an @c XMOSKeywordDetector
*
* @param stream The stream of audio data. This should be formatted in LPCM encoded with 16 bits per sample and
* have a sample rate of 16 kHz. Additionally, the data should be in little endian format.
* @param audioFormat The format of the audio data located within the stream.
* @param keyWordNotifier The object with which to notifiy observers of keyword detections.
* @param KeyWordDetectorStateNotifier The object with which to notify observers of state changes in the engine.
* @param msToPushPerIteration The amount of data in milliseconds to push to the cloud at a time. This was the amount used by
* Sensory in example code.
*/
static std::unique_ptr<XMOSKeywordDetector> create(
const std::shared_ptr<AudioInputStream> stream,
const std::shared_ptr<avsCommon::utils::AudioFormat>& audioFormat,
std::shared_ptr<acsdkKWDInterfaces::KeywordNotifierInterface> keyWordNotifier,
std::shared_ptr<acsdkKWDInterfaces::KeywordDetectorStateNotifierInterface> KeyWordDetectorStateNotifier,
std::chrono::milliseconds msToPushPerIteration = std::chrono::milliseconds(10));

/**
* @deprecated
* Creates an @c XMOSKeywordDetector
*
* @param stream The stream of audio data. This should be formatted in LPCM encoded with 16 bits per sample and
* have a sample rate of 16 kHz. Additionally, the data should be in little endian format.
* @param audioFormat The format of the audio data located within the stream.
* @param keyWordObservers The observers to notify of keyword detections.
* @param keyWordDetectorStateObservers The observers to notify of state changes in the engine.
* @param msToPushPerIteration The amount of data in milliseconds to push to the cloud at a time. This was the amount used by
* Sensory in example code.
* @return A new @c XMOSKeywordDetector, or @c nullptr if the operation failed.
*/
static std::unique_ptr<XMOSKeywordDetector> create(
const std::shared_ptr<AudioInputStream> stream,
avsCommon::utils::AudioFormat audioFormat,
std::unordered_set<std::shared_ptr<KeyWordObserverInterface>> keyWordObservers,
std::unordered_set<std::shared_ptr<KeyWordDetectorStateObserverInterface>> keyWordDetectorStateObservers,
std::chrono::milliseconds msToPushPerIteration = std::chrono::milliseconds(10));

/**
* Destructor.
*/
Expand Down
59 changes: 19 additions & 40 deletions tools/Install/pi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,6 @@ if [ -z "$PLATFORM" ]; then
exit 1
fi

show_help() {
echo 'Usage: pi.sh [OPTIONS]'
echo ''
echo 'Optional parameters'
echo ' -G Flag to enable keyword detector on GPIO interrupt'
echo ' -H Flag to enable keyword detector on HID event'
echo ' -S Flag to enable Sensory keyword detector'
echo ' -h Display this help and exit'
}
OPTIONS=GHSh
while getopts "$OPTIONS" opt ; do
case $opt in
G )
GPIO_KEY_WORD_DETECTOR_FLAG="ON"
;;
H )
HID_KEY_WORD_DETECTOR_FLAG="ON"
;;
S )
SENSORY_KEY_WORD_DETECTOR_FLAG="ON"
;;

h )
show_help
exit 1
;;
esac
done

SOUND_CONFIG="$HOME/.asoundrc"
START_SCRIPT="$INSTALL_BASE/startsample.sh"
START_PREVIEW_SCRIPT="$INSTALL_BASE/startpreview.sh"
Expand All @@ -64,18 +35,26 @@ CMAKE_PLATFORM_SPECIFIC=(-DGSTREAMER_MEDIA_PLAYER=ON \
-DCURL_LIBRARY=${THIRD_PARTY_PATH}/curl-${CURL_VER}/lib/.libs/libcurl.so)

# Add the flags for the different keyword detectors
if [ -n "$SENSORY_KEY_WORD_DETECTOR_FLAG" ]
then
CMAKE_PLATFORM_SPECIFIC+=(-DSENSORY_KEY_WORD_DETECTOR=ON \
case $KEY_WORD_DETECTOR_FLAG in
S )
# Set CMAKE options for Sensory Keyword detector
CMAKE_PLATFORM_SPECIFIC+=(-DSENSORY_KEY_WORD_DETECTOR=ON \
-DSENSORY_OP_POINT=ON \
-DXMOS_AVS_TESTS=ON \
-DSENSORY_KEY_WORD_DETECTOR_LIB_PATH=$THIRD_PARTY_PATH/alexa-rpi/lib/libsnsr.a \
-DSENSORY_KEY_WORD_DETECTOR_INCLUDE_DIR=$THIRD_PARTY_PATH/alexa-rpi/include)
elif [ -n "$GPIO_KEY_WORD_DETECTOR_FLAG" ]
then
CMAKE_PLATFORM_SPECIFIC+=(-DGPIO_KEY_WORD_DETECTOR=ON)
elif [ -n "$HID_KEY_WORD_DETECTOR_FLAG" ]
then
CMAKE_PLATFORM_SPECIFIC+=(-DHID_KEY_WORD_DETECTOR=ON)
fi
;;
A )
# Set CMAKE options for Amazon Keyword detector
CMAKE_PLATFORM_SPECIFIC+=""
;;
G )
CMAKE_PLATFORM_SPECIFIC+=(-DGPIO_KEY_WORD_DETECTOR=ON)
;;
H )
CMAKE_PLATFORM_SPECIFIC+=(-DHID_KEY_WORD_DETECTOR=ON)
;;
esac

GSTREAMER_AUDIO_SINK="alsasink"

Expand All @@ -87,7 +66,7 @@ install_dependencies() {
run_os_specifics() {
build_port_audio
build_curl
if [ [ -z $GPIO_KEY_WORD_DETECTOR_FLAG ] && [ -z $HID_KEY_WORD_DETECTOR_FLAG ] && [ -z $SENSORY_KEY_WORD_DETECTOR_FLAG ] ]
if [ [ -z $KEY_WORD_DETECTOR_FLAG ] ]
then
echo
echo "==============> TAP-TO-TALK IS ENABLED =============="
Expand Down
57 changes: 22 additions & 35 deletions tools/Install/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ set -o nounset # Exit the script if any uninitialized variable is used.

CLONE_URL=${CLONE_URL:- 'https://github.com/xmos/avs-device-sdk.git'}

PORT_AUDIO_FILE="pa_stable_v190600_20161030.tgz"
PORT_AUDIO_DOWNLOAD_URL="http://www.portaudio.com/archives/$PORT_AUDIO_FILE"
# Download portaudio from github as it is more reliable than the website
# Comment out old variables
# PORT_AUDIO_FILE="pa_stable_v190600_20161030.tgz"
# PORT_AUDIO_DOWNLOAD_URL="https://github.com/PortAudio/portaudio/releases/tag/pa_stable_v190600_20161030"
PORT_AUDIO_TAG="pa_stable_v190600_20161030"
PORT_AUDIO_CLONE_URL="https://github.com/PortAudio/portaudio"
PORT_AUDIO_DIR="portaudio"

CURL_VER=7.67.0
CURL_DOWNLOAD_URL="https://github.com/curl/curl/releases/download/curl-7_67_0/curl-${CURL_VER}.tar.gz"
Expand Down Expand Up @@ -62,9 +67,6 @@ PATH_FILES_DIR="$HOME/.config/"
VOCALFUSION_3510_SALES_DEMO_PATH_FILE="$PATH_FILES_DIR/vocalfusion_3510_sales_demo_path"
VOCALFUSION_3510_AVS_SETUP_PATH_FILE="$PATH_FILES_DIR/vocalfusion_3510_avs_setup_path"
PI_HAT_CTRL_PATH="$THIRD_PARTY_PATH/pi_hat_ctrl"
SENSORY_KEY_WORD_DETECTOR_FLAG=""
GPIO_KEY_WORD_DETECTOR_FLAG=""
HID_KEY_WORD_DETECTOR_FLAG=""
ALIASES="$HOME/.bash_aliases"

# Default value for XMOS device
Expand Down Expand Up @@ -93,10 +95,13 @@ build_port_audio() {
echo "==============> BUILDING PORT AUDIO =============="
echo
pushd $THIRD_PARTY_PATH
wget -c $PORT_AUDIO_DOWNLOAD_URL
tar zxf $PORT_AUDIO_FILE
# Download portaudio from github as it is more reliable than the website
# Comment out old lines
# wget -c $PORT_AUDIO_DOWNLOAD_URL
# tar zxf $PORT_AUDIO_FILE

pushd portaudio
git clone -b $PORT_AUDIO_TAG $PORT_AUDIO_CLONE_URL
pushd $PORT_AUDIO_DIR
./configure --without-jack
make
popd
Expand Down Expand Up @@ -137,9 +142,7 @@ show_help() {
echo ' -i <user-pin> PKCS#11 user pin to access key object functions.'
echo ' -k <key-name> PKCS#11 key object label.'
echo ' -x <xmos-device-type> XMOS device to setup: possible values are xvf3100, xvf3500, xvf3510, xvf3600-slave, xvf3600-master, or xvf3610, default is xvf3510'
echo ' -G Flag to enable keyword detector on GPIO interrupt'
echo ' -H Flag to enable keyword detector on HID interrupt'
echo ' -S Flag to enable Sensory keyword detector'
echo ' -w <keyword-detector-type> Keyword detector to setup: possible values are S (Sensory), A (Amazon), G (GPIO trigger), H (HID trigger), default is no keyword detector, only tap-to-talk is enabled'
echo ' -h Display this help and exit'
}

Expand All @@ -159,7 +162,9 @@ XMOS_TAG=$2

shift 2

OPTIONS=s:a:d:hp:k:i:t:m:x:GHSh
KEY_WORD_DETECTOR_FLAG=""

OPTIONS=s:a:d:hp:k:i:t:m:x:w:h
while getopts "$OPTIONS" opt ; do
case $opt in
s )
Expand All @@ -182,14 +187,8 @@ while getopts "$OPTIONS" opt ; do
x )
XMOS_DEVICE="$OPTARG"
;;
G )
GPIO_KEY_WORD_DETECTOR_FLAG="-G"
;;
H )
HID_KEY_WORD_DETECTOR_FLAG="-H"
;;
S )
SENSORY_KEY_WORD_DETECTOR_FLAG="-S"
w )
KEY_WORD_DETECTOR_FLAG="$OPTARG"
;;
h )
show_help
Expand Down Expand Up @@ -263,8 +262,8 @@ PLATFORM=${PLATFORM:-$(get_platform)}

if [ "$PLATFORM" == "Raspberry pi" ]
then
PI_CMD="pi.sh ${SENSORY_KEY_WORD_DETECTOR_FLAG} ${GPIO_KEY_WORD_DETECTOR_FLAG} ${HID_KEY_WORD_DETECTOR_FLAG}"
echo "Running command ${PI_CMD}"
PI_CMD="pi.sh"
echo "Running command \"${PI_CMD}\" with KEY_WORD_DETECTOR_FLAG set to \"${KEY_WORD_DETECTOR_FLAG}\""
source $PI_CMD
elif [ "$PLATFORM" == "Windows mingw64" ]
then
Expand Down Expand Up @@ -335,8 +334,7 @@ echo
AUTOSTART_SESSION="avsrun"
AUTOSTART_DIR=$HOME/.config/lxsession/LXDE-pi
AUTOSTART=$AUTOSTART_DIR/autostart
AVSRUN_CMD="lxterminal -t avsrun -e \"$BUILD_PATH/SampleApp/src/SampleApp $OUTPUT_CONFIG_FILE "
AVSRUN_CMD+="NONE\" &"
AVSRUN_CMD="lxterminal -t avsrun -e \"$BUILD_PATH/SampleApp/src/SampleApp $OUTPUT_CONFIG_FILE NONE\" & "

STARTUP_SCRIPT=$CURRENT_DIR/.avsrun-startup.sh
if [ ! -f $AUTOSTART ]; then
Expand Down Expand Up @@ -399,15 +397,6 @@ while true; do
esac
done

if [ -n "$SENSORY_KEY_WORD_DETECTOR_FLAG" ]
then
SENSORY_OP_POINT_FLAG="-DSENSORY_OP_POINT=ON"
XMOS_AVS_TESTS_FLAG="-DXMOS_AVS_TESTS=ON"
else
SENSORY_OP_POINT_FLAG="-DSENSORY_OP_POINT=OFF"
XMOS_AVS_TESTS_FLAG="-DXMOS_AVS_TESTS=OFF"
fi

if [ $XMOS_DEVICE = "xvf3510" ]
then
PI_HAT_FLAG="-DPI_HAT_CTRL=ON"
Expand Down Expand Up @@ -465,9 +454,7 @@ then
mkdir -p $BUILD_PATH
cd $BUILD_PATH
cmake "$SOURCE_PATH/avs-device-sdk" \
$SENSORY_OP_POINT_FLAG \
$PI_HAT_FLAG \
$XMOS_AVS_TESTS_FLAG \
-DCMAKE_BUILD_TYPE=DEBUG \
-DPKCS11=$ACSDK_PKCS11 \
"${CMAKE_PLATFORM_SPECIFIC[@]}"
Expand Down

0 comments on commit ccd8e71

Please sign in to comment.