Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake + PortAudio #70

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [jwinarske] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ run_assistant_audio
run_assistant_file
run_assistant_text
# Generated files
src/embedded_assistant*
src/embedded_assistant*
build
.DS_Store

48 changes: 48 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
language: cpp

os:
- linux
- osx

compiler:
- gcc
- clang

env:
- BUILD_TYPE=Debug
- BUILD_TYPE=Release
- BUILD_TYPE=MinSizeRel

addons:
apt:
packages:
- libasound2-dev

install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir ${DEPS_DIR} && cd ${DEPS_DIR} && pwd; fi

- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_retry wget --no-check-certificate https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-x86_64.tar.gz; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "06bb006122e8e094f942bc9b2d999c92 *cmake-3.17.3-Linux-x86_64.tar.gz" > cmake_md5.txt; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then md5sum -c cmake_md5.txt; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xvf cmake-3.17.3-Linux-x86_64.tar.gz > /dev/null; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mv cmake-3.17.3-Linux-x86_64 cmake-install; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then PATH=${DEPS_DIR}/cmake-install:${DEPS_DIR}/cmake-install/bin:$PATH; fi

- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_retry wget --no-check-certificate https://golang.org/dl/go1.14.4.linux-amd64.tar.gz; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "0ea61d0d7e05bbe454b8b19569ad86c8 *go1.14.4.linux-amd64.tar.gz" > go_md5.txt; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then md5sum -c go_md5.txt; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf go1.14.4.linux-amd64.tar.gz > /dev/null; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export GOROOT=${DEPS_DIR}/go; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then PATH=${DEPS_DIR}/go/bin:$PATH; fi

before_script:
- cd ${TRAVIS_BUILD_DIR}
- mkdir build && cd build
- cmake ..
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DCMAKE_STAGING_PREFIX=${TRAVIS_BUILD_DIR}/dist/usr/local

script:
- cmake --build . --config ${BUILD_TYPE} --target install
111 changes: 111 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
cmake_minimum_required(VERSION 3.10.2)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE)
message(STATUS "CMAKE_BUILD_TYPE not set, defaulting to MinSizeRel.")
endif()

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake")

if(NOT BUILD_NUMBER)
set(BUILD_NUMBER 0)
endif()
set(ASSISTANT_SDK_CPP_VERSION 0.0.1.${BUILD_NUMBER})

set(PACKAGE_NAME assistant-sdk-cpp)
project(${PACKAGE_NAME} VERSION "${ASSISTANT_SDK_CPP_VERSION}" LANGUAGES CXX C)

message(STATUS "Generator .............. ${CMAKE_GENERATOR}")
message(STATUS "Build Type ............. ${CMAKE_BUILD_TYPE}")
include (target_arch)
get_target_arch(TARGET_ARCH)
message(STATUS "Target ................. ${TARGET_ARCH}")

include(build_dependencies)

set(CMAKE_CXX_STANDARD_REQUIRED 11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
include(FindThreads)

include(googleapis)

protobuf_generate_grpc_cpp(
${PROTO_BASE_PATH}/google/api/http.proto
${PROTO_BASE_PATH}/google/api/annotations.proto
${PROTO_BASE_PATH}/google/type/latlng.proto
${PROTO_BASE_PATH}/google/assistant/embedded/v1alpha2/embedded_assistant.proto
)
set(GOOGLEAPIS_CCS
${_gRPC_PROTO_GENS_DIR}/google/api/http.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/google/api/http.pb.cc
${_gRPC_PROTO_GENS_DIR}/google/api/annotations.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/google/api/annotations.pb.cc
${_gRPC_PROTO_GENS_DIR}/google/type/latlng.pb.cc
${_gRPC_PROTO_GENS_DIR}/google/type/latlng.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/google/assistant/embedded/v1alpha2/embedded_assistant.pb.cc
${_gRPC_PROTO_GENS_DIR}/google/assistant/embedded/v1alpha2/embedded_assistant.grpc.pb.cc
)
set_source_files_properties(${GOOGLEAPIS_CCS} PROPERTIES GENERATED TRUE)
include_directories(${_gRPC_PROTO_GENS_DIR})

set(CORE_SRCS src/base64_encode.cc)
set(AUDIO_INPUT_FILE_SRCS src/audio_input_file.cc)
set(ASSISTANT_AUDIO_SRCS src/run_assistant_audio.cc src/audio_pa.cc)
set(ASSISTANT_FILE_SRCS src/run_assistant_file.cc)
set(ASSISTANT_TEXT_SRCS src/run_assistant_text.cc)

include_directories(
src
${CMAKE_CURRENT_BINARY_DIR}/grpc_ext-prefix/src/grpc_ext/third_party/abseil-cpp
)

if(WIN32 AND MSVC)
add_definitions(-D_WIN32_WINNT=0x600)
set(_ALLTARGETS_LIBRARIES ${_GPERF_LIBRARY})
list(APPEND EXE_DEPS gperf_ext portaudio_ext)
elseif(APPLE)
set(_ALLTARGETS_LIBRARIES ${CMAKE_DL_LIBS} m ${CMAKE_THREAD_LIBS_INIT})
elseif(ANDROID)
set(_ALLTARGETS_LIBRARIES ${CMAKE_DL_LIBS} m log)
else()
set(_ALLTARGETS_LIBRARIES ${CMAKE_DL_LIBS} rt m ${CMAKE_THREAD_LIBS_INIT})
endif()

set(LDFLAGS
grpc++ grpc address_sorting upb cares gpr
${_ABSL_LIBRARIES} ${_PROTOBUF_LIBRARIES}
${_ZLIB_LIBRARIES} ${_SSL_LIBRARIES}
${_ALLTARGETS_LIBRARIES}
)

if(NOT HAVE_GETOPT_C)
set(EXT_DEPS gperf_ext)
endif()
set(EXT_DEPS ${EXT_DEPS} portaudio_ext)

add_executable(run_assistant_text ${GOOGLEAPIS_CCS} ${CORE_SRCS} ${ASSISTANT_TEXT_SRCS})
target_link_libraries(run_assistant_text ${LDFLAGS})
add_dependencies(run_assistant_text ${EXT_DEPS})

add_executable(run_assistant_file ${GOOGLEAPIS_CCS} ${CORE_SRCS} ${AUDIO_INPUT_FILE_SRCS} ${ASSISTANT_FILE_SRCS})
target_link_libraries(run_assistant_file ${LDFLAGS})
add_dependencies(run_assistant_file ${EXT_DEPS})

add_executable(run_assistant_audio ${GOOGLEAPIS_CCS} ${CORE_SRCS} ${AUDIO_SRCS} ${ASSISTANT_AUDIO_SRCS})
target_link_libraries(run_assistant_audio ${LDFLAGS} ${_PORTAUDIO_LIB})
add_dependencies(run_assistant_audio ${EXT_DEPS})

if(APPLE)
target_link_libraries(run_assistant_text "-framework CoreFoundation")
target_link_libraries(run_assistant_file "-framework CoreFoundation")
target_link_libraries(run_assistant_audio "-framework CoreFoundation")
endif()

install (TARGETS run_assistant_audio run_assistant_text run_assistant_file
RUNTIME DESTINATION bin
)

add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/make_uninstall.cmake")
64 changes: 21 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Google Assistant SDK for devices - C++

### Linux / OSX build status
[![Build Status](https://travis-ci.com/jwinarske/assistant-sdk-cpp.svg?branch=cmake)](https://travis-ci.com/jwinarske/assistant-sdk-cpp)

### Windows build status
[![Build status](https://ci.appveyor.com/api/projects/status/op7vmksh3p0jkln4/branch/cmake?svg=true)](https://ci.appveyor.com/project/jwinarske/assistant-sdk-cpp/branch/cmake)

## Requirements

This project is officially supported on Ubuntu 14.04. Other Linux distributions may be able to run
Expand Down Expand Up @@ -29,7 +35,6 @@ sudo rm -rf /usr/local/bin/grpc_* /usr/local/bin/protoc \
```
git clone https://github.com/googlesamples/assistant-sdk-cpp.git
cd assistant-sdk-cpp
export PROJECT_PATH=$(pwd)
```

2. Install dependencies
Expand All @@ -39,78 +44,51 @@ sudo apt-get install libasound2-dev # For ALSA sound output
sudo apt-get install libcurl4-openssl-dev # CURL development library
```

3. Build Protocol Buffer, gRPC, and Google APIs
```
git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
GRPC_PATH=${PROJECT_PATH}/grpc
cd ${GRPC_PATH}

git submodule update --init

cd third_party/protobuf
./autogen.sh && ./configure && make
sudo make install
sudo ldconfig

export LDFLAGS="$LDFLAGS -lm"
cd ${GRPC_PATH}
make clean
make
sudo make install
sudo ldconfig

cd ${PROJECT_PATH}
git clone https://github.com/googleapis/googleapis.git
cd googleapis/
make LANGUAGE=cpp
```

4. Make sure you setup environment variable `$GOOGLEAPIS_GENS_PATH`
```
export GOOGLEAPIS_GENS_PATH=${PROJECT_PATH}/googleapis/gens
```

5. Build this project
3. Build this project
```
cd ${PROJECT_PATH}
make run_assistant
mkdir build && cd build
cmake .. -DCMAKE_STAGING_PREFIX=`pwd`/dist/usr/local
make install -j
```

6. Get credentials file. It must be an end-user's credentials.
4. Get credentials file. It must be an end-user's credentials.

* Go to the [Actions Console](https://console.actions.google.com/) and register your device model, following [these instructions](https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device)
* Move it in this folder and rename it to `client_secret.json`
* run `get_credentials.sh` in this folder. It will create the file `credentials.json`.

7. Start one of the `run_assistant` samples:
5. Start one of the `run_assistant` samples:

```bash
./run_assistant_file --input ./resources/weather_in_mountain_view.raw --output ./response.wav --credentials ./credentials.json
export LD_LIBRARY_PATH=`pwd`/dist/usr/local/lib
./dist/usr/local/bin/run_assistant_file --input ../resources/weather_in_mountain_view.raw --output ./response.wav --credentials ../credentials.json
aplay ./response.wav --rate=16000 --format=S16_LE
```

On a Linux workstation, you can alternatively use ALSA for audio input:

```bash
./run_assistant_audio --credentials ./credentials.json
export LD_LIBRARY_PATH=`pwd`/dist/usr/local/lib
./dist/usr/local/bin/run_assistant_audio --credentials ../credentials.json
```

You can use a text-based query instead of audio. This allows you to continually enter text queries to the Assistant.

```bash
./run_assistant_text --credentials ./credentials.json
export LD_LIBRARY_PATH=`pwd`/dist/usr/local/lib
./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json
```

This takes input from `cin`, so you can send data to the program when it starts.

```bash
echo "what time is it" | ./run_assistant_text --credentials ./credentials.json
echo "what time is it" | ./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json
```

To change the locale, include a `locale` parameter:

```bash
echo "Bonjour" | ./run_assistant_text --credentials ./credentials.json --locale "fr-FR"
echo "Bonjour" | ./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json --locale "fr-FR"
```

Default Assistant gRPC API endpoint is `embeddedassistant.googleapis.com`. If you want to test with a custom Assistant gRPC API endpoint, you can pass `--api_endpoint CUSTOM_API_ENDPOINT`.
Expand All @@ -120,7 +98,7 @@ Default Assistant gRPC API endpoint is `embeddedassistant.googleapis.com`. If yo
To get a visual output from the Assistant, provide a command to be run alongside every step of the conversation. It will execute that command along along with a provided argument of a temporary HTML file.

```bash
echo "what time is it" | ./run_assistant_text --credentials ./credentials.json --html_out google-chrome
echo "what time is it" | ./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json --html_out google-chrome
```

After you enter text, it will run `google-chrome /tmp/google-assistant-cpp-screen-out.html`.
Expand Down
Loading