o ffmpeg, faz a conversão do texto no formato desejado para analise. O arquivo é preparado para uma taxa de amostragem de 16k.
Lendo o arquivo
pocketsphinx_continuous -infile jfk.wav > jfk.txt
Segue o que ele ouviu
i got an r n n n not because they are easy one because they are hot the car and gold wilson to organize then it then asked our energy density else we got it at our ideas and won that we’re willing to exactly while we are unwilling to postpone and one nintendo wii in and then look
Podemos perceber que neste primeiro processo ele ouviu muita coisa errada, porem algumas palavras de cara deram certo. “not because they are easy”. Porem a qualidade do audio comprometeu em muito a leitura.
O parametro -infile, permite ler o arquivo origem, porem o mesmo precisa ser previamente preparado para leitura deste.
Pudemos verificar que a qualidade do audio foi importante para refletir a acuracia do audio, iremos pegar algo mais simples agora.
Segundo exemplo
Neste segundo exemplo extraímos o audio do seguinte link:
Temos visto uma crescente de IoT desenvolvidos especificamente para reconhecer comandos de seu dono, tais dispositivos, como Alexa ou o Google Home, tem se tornado, bem popular.
Iremos neste artigo, aprender a criar nosso próprio google home.
O que é o CMU Sphinx
CMU Sphinx é uma api de reconhecimento de voz. Ela é bastante consagrada, possuindo muitos projetos atrelados a ela.
Trato a biblioteca com bastante foco para desenvolvimento IoT, no meu livro que pode ser baixado livremente.
A grande vantagem desta api, é que ela não necessita de conexão externa ou acesso a internet.
Uso do CMU Sphinx
Utilizaremos o CMU Sphinx como base do nosso projeto.
Para atender a instalação será necessário as seguintes bibliotecas:
apt install bison
apt install libasound2-dev
apt install swig
apt install python
Pré requisitos de instalação
Instalação do Sphinx pelo gerenciador de pacotes
A instalação do sphinx pelo gerenciador de pacote, fica bem mais fácil, porem pode ser necessário, atualizar manualmente a versão, pois ninguem garante que o repositório estará atualizado com a ultima versão.
apt install shinxbase*
apt install pocketsphinx*
instalação através do gerenciador de pacotes
Baixa manual
Nesta modalidade iremos baixar e instalar o sphinx manualmente em nosso linux.
Ninja é um pequeno conjunto de ferramentas, desenvolvido por Evan Martin, um empregado da Google. Ninja foi usado em diversas construções de aplicações.
Entre suas vantagens estão a facilidade de montagem de aplicação, a velocidade e rapidez.
Outra vantagem é a capacidade de construir aplicações em multiplos SOs. (Windows, Linux, MacOS).
Iremos apresentar um pequeno projeto construído com NINJA.
O srvOuve é um projeto que visa integrar o CMU sphinx, estaremos construindo uma build com ninja.
Primeiramente precisamos criar o arquivo CMakeLists.txt , que fará a magica acontecer.
Criamos o arquivo conforme aparece no fragmento abaixo:
cmake_minimum_required (VERSION 3.8)
#Define o projeto
project(srvOuve VERSION 1.0)
#Diretorios de Include
include_directories( "/usr/local/include/pocketsphinx"
"/usr/local/include/sphinxbase"
)
set(CMAKE_CXX_STANDARD 14)
add_executable(srvOuve ouve.cpp)
Agora precisaremos dizer ao sistema para gerar os arquivos do ninja, para tanto chamamos o cmake, conforme a sintaxe abaixo:
$ cmake -G Ninja
Execução na console
Com este passo o cmake criará dois arquivos:
build.ninja – Este arquivo contem as configurações de compilação (build)
O build.ninja conterá as regras de construção da aplicação.
# CMAKE generated file: DO NOT EDIT!
# Generated by "Ninja" Generator, CMake Version 3.10
# This file contains all the build statements describing the
# compilation DAG.
# =============================================================================
# Write statements declared in CMakeLists.txt:
#
# Which is the root file.
# =============================================================================
# =============================================================================
# Project: srvOuve
# Configuration:
# =============================================================================
#############################################
# Minimal version of Ninja required by this file
ninja_required_version = 1.5
# =============================================================================
# Include auxiliary files.
#############################################
# Include rules file.
include rules.ninja
#############################################
# Utility command for rebuild_cache
build CMakeFiles/rebuild_cache.util: CUSTOM_COMMAND
COMMAND = cd /home/maurinsoft/projetos/srvOuve/srv && /usr/bin/cmake -H/home/maurinsoft/projetos/srvOuve/srv -B/home/maurinsoft/projetos/srvOuve/srv
DESC = Running CMake to regenerate build system...
pool = console
restat = 1
build rebuild_cache: phony CMakeFiles/rebuild_cache.util
# =============================================================================
# Object build statements for EXECUTABLE target srvOuve
#############################################
# Order-only phony target for srvOuve
build cmake_object_order_depends_target_srvOuve: phony
build CMakeFiles/srvOuve.dir/ouve.cpp.o: CXX_COMPILER__srvOuve ouve.cpp || cmake_object_order_depends_target_srvOuve
DEP_FILE = CMakeFiles/srvOuve.dir/ouve.cpp.o.d
FLAGS = -std=gnu++14
INCLUDES = -I/usr/local/include/pocketsphinx -I/usr/local/include/sphinxbase
OBJECT_DIR = CMakeFiles/srvOuve.dir
OBJECT_FILE_DIR = CMakeFiles/srvOuve.dir
# =============================================================================
# Link build statements for EXECUTABLE target srvOuve
#############################################
# Link the executable srvOuve
build srvOuve: CXX_EXECUTABLE_LINKER__srvOuve CMakeFiles/srvOuve.dir/ouve.cpp.o
OBJECT_DIR = CMakeFiles/srvOuve.dir
POST_BUILD = :
PRE_LINK = :
TARGET_FILE = srvOuve
TARGET_PDB = srvOuve.dbg
#############################################
# Utility command for edit_cache
build CMakeFiles/edit_cache.util: CUSTOM_COMMAND
COMMAND = cd /home/maurinsoft/projetos/srvOuve/srv && /usr/bin/cmake-gui -H/home/maurinsoft/projetos/srvOuve/srv -B/home/maurinsoft/projetos/srvOuve/srv
DESC = Running CMake cache editor...
pool = console
restat = 1
build edit_cache: phony CMakeFiles/edit_cache.util
# =============================================================================
# Target aliases.
# =============================================================================
# Folder targets.
# =============================================================================
# =============================================================================
# Built-in targets
#############################################
# The main all target.
build all: phony srvOuve
#############################################
# Make the all target the default.
default all
#############################################
# Re-run CMake if any of its inputs changed.
build build.ninja: RERUN_CMAKE | /usr/share/cmake-3.10/Modules/CMakeCInformation.cmake /usr/share/cmake-3.10/Modules/CMakeCXXInformation.cmake /usr/share/cmake-3.10/Modules/CMakeCommonLanguageInclude.cmake /usr/share/cmake-3.10/Modules/CMakeGenericSystem.cmake /usr/share/cmake-3.10/Modules/CMakeLanguageInformation.cmake /usr/share/cmake-3.10/Modules/CMakeSystemSpecificInformation.cmake /usr/share/cmake-3.10/Modules/CMakeSystemSpecificInitialize.cmake /usr/share/cmake-3.10/Modules/Compiler/CMakeCommonCompilerMacros.cmake /usr/share/cmake-3.10/Modules/Compiler/GNU-C.cmake /usr/share/cmake-3.10/Modules/Compiler/GNU-CXX.cmake /usr/share/cmake-3.10/Modules/Compiler/GNU.cmake /usr/share/cmake-3.10/Modules/Platform/Linux-GNU-C.cmake /usr/share/cmake-3.10/Modules/Platform/Linux-GNU-CXX.cmake /usr/share/cmake-3.10/Modules/Platform/Linux-GNU.cmake /usr/share/cmake-3.10/Modules/Platform/Linux.cmake /usr/share/cmake-3.10/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/3.10.2/CMakeCCompiler.cmake CMakeFiles/3.10.2/CMakeCXXCompiler.cmake CMakeFiles/3.10.2/CMakeSystem.cmake CMakeLists.txt
pool = console
#############################################
# A missing CMake input file is not an error.
build /usr/share/cmake-3.10/Modules/CMakeCInformation.cmake /usr/share/cmake-3.10/Modules/CMakeCXXInformation.cmake /usr/share/cmake-3.10/Modules/CMakeCommonLanguageInclude.cmake /usr/share/cmake-3.10/Modules/CMakeGenericSystem.cmake /usr/share/cmake-3.10/Modules/CMakeLanguageInformation.cmake /usr/share/cmake-3.10/Modules/CMakeSystemSpecificInformation.cmake /usr/share/cmake-3.10/Modules/CMakeSystemSpecificInitialize.cmake /usr/share/cmake-3.10/Modules/Compiler/CMakeCommonCompilerMacros.cmake /usr/share/cmake-3.10/Modules/Compiler/GNU-C.cmake /usr/share/cmake-3.10/Modules/Compiler/GNU-CXX.cmake /usr/share/cmake-3.10/Modules/Compiler/GNU.cmake /usr/share/cmake-3.10/Modules/Platform/Linux-GNU-C.cmake /usr/share/cmake-3.10/Modules/Platform/Linux-GNU-CXX.cmake /usr/share/cmake-3.10/Modules/Platform/Linux-GNU.cmake /usr/share/cmake-3.10/Modules/Platform/Linux.cmake /usr/share/cmake-3.10/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/3.10.2/CMakeCCompiler.cmake CMakeFiles/3.10.2/CMakeCXXCompiler.cmake CMakeFiles/3.10.2/CMakeSystem.cmake CMakeLists.txt: phony
#############################################
# Clean all the built files.
build clean: CLEAN
#############################################
# Print all primary targets available.
build help: HELP
O cmake tambem cria o arquivo rules.ninja, responsável pelas regras de compilação.
# CMAKE generated file: DO NOT EDIT!
# Generated by "Ninja" Generator, CMake Version 3.10
# This file contains all the rules used to get the outputs files
# built from the input files.
# It is included in the main 'build.ninja'.
# =============================================================================
# Project: srvOuve
# Configuration:
# =============================================================================
# =============================================================================
#############################################
# Rule for running custom commands.
rule CUSTOM_COMMAND
command = $COMMAND
description = $DESC
#############################################
# Rule for compiling CXX files.
rule CXX_COMPILER__srvOuve
depfile = $DEP_FILE
deps = gcc
command = /usr/bin/c++ $DEFINES $INCLUDES $FLAGS -MD -MT $out -MF $DEP_FILE -o $out -c $in
description = Building CXX object $out
#############################################
# Rule for linking CXX executable.
rule CXX_EXECUTABLE_LINKER__srvOuve
command = $PRE_LINK && /usr/bin/c++ $FLAGS $LINK_FLAGS $in -o $TARGET_FILE $LINK_PATH $LINK_LIBRARIES && $POST_BUILD
description = Linking CXX executable $TARGET_FILE
restat = $RESTAT
#############################################
# Rule for re-running cmake.
rule RERUN_CMAKE
command = /usr/bin/cmake -H/home/maurinsoft/projetos/srvOuve/srv -B/home/maurinsoft/projetos/srvOuve/srv
description = Re-running CMake...
generator = 1
#############################################
# Rule for cleaning all built files.
rule CLEAN
command = /usr/bin/ninja -t clean
description = Cleaning all built files...
#############################################
# Rule for printing all primary targets available.
rule HELP
command = /usr/bin/ninja -t targets
description = All primary targets available:
Para processar o ninja precisamos fazer uma pequena mudança, alterar as extensões de .c para .cpp, para que o sistema identifique que se trata de compilador C.
Incluindo dependências
Para incluir diretorios para Include, basta incluir a linha