Skip to content

Commit

Permalink
Refactor build script for Linux and MacOS in CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Sep 24, 2024
1 parent 0c96957 commit e349b96
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 12 deletions.
4 changes: 4 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ include(${CMAKE_SOURCE_DIR}/cmake/BuildSDL.cmake)

add_executable(RealtimeTranscription realtime_transcription.cpp audio_capture.cpp)
target_link_libraries(RealtimeTranscription PRIVATE SDL2 Core Transcription)

# add target "examples" to the global target list
add_custom_target(examples)
add_dependencies(examples RealtimeTranscription)
2 changes: 2 additions & 0 deletions examples/audio_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ AudioCapture::~AudioCapture() {
}

bool AudioCapture::initialize(int device_index, int requested_sample_rate) {
SDL_InitSubSystem(SDL_INIT_AUDIO);

SDL_AudioSpec desired_spec, obtained_spec;

SDL_zero(desired_spec);
Expand Down
1 change: 0 additions & 1 deletion examples/audio_capture.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#define SDL_MAIN_HANDLED
#include <SDL.h>

#include <atomic>
Expand Down
4 changes: 3 additions & 1 deletion examples/realtime_transcription.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <locaal.h>

#define SDL_MAIN_HANDLED
#include "audio_capture.h"

#include <iostream>

int main()
{
SDL_SetMainReady();
// SDL_SetMainReady();

// Initialize the library
locaal::Transcription tt;
Expand Down
6 changes: 5 additions & 1 deletion scripts/build-windows.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
param(
[switch]$Verbose,
[switch]$Clean
[switch]$Clean,
[switch]$Examples
)

$verboseFlag = ""
Expand Down Expand Up @@ -33,5 +34,8 @@ Invoke-Expression $configureCommand

# Build step
$buildCommand = "cmake --build $buildDir --config Release $verboseBuildFlag"
if ($Examples) {
$buildCommand += " --target examples"
}
Write-Host "Executing build command: $buildCommand"
Invoke-Expression $buildCommand
3 changes: 3 additions & 0 deletions src/modules/transcription/include/transcription.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string>
#include <functional>

struct transcription_context;

namespace locaal {

struct TranscriptionResult {
Expand Down Expand Up @@ -41,6 +43,7 @@ class Transcription {
std::function<void(const TranscriptionResult &)> transcriptionCallback_;

// Add any other necessary private members
transcription_context *gf;
};

} // namespace locaal
Expand Down
4 changes: 3 additions & 1 deletion src/modules/transcription/include/whisper-processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ struct DetectionResultWithText {
std::string language;
};

void whisper_loop(void *data);
struct transcription_context;

void whisper_loop(struct transcription_context *gf);
struct whisper_context *init_whisper_context(const std::string &model_path,
struct transcription_context *gf);
void run_inference_and_callbacks(transcription_context *gf, uint64_t start_offset_ms,
Expand Down
23 changes: 20 additions & 3 deletions src/modules/transcription/src/transcription.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
#include "transcription.h"
#include "logger.h"
#include "transcription-context.h"
#include "whisper-utils.h"

#include <iostream>

void set_text_callback(struct transcription_context *gf, const DetectionResultWithText &str)
{
Logger::log(Logger::Level::INFO, "Transcription: %s", str.text.c_str());
}

void clear_current_caption(transcription_context *gf_){};

// Callback sent when the VAD finds an audio chunk. Sample rate = WHISPER_SAMPLE_RATE, channels = 1
// The audio chunk is in 32-bit float format
void audio_chunk_callback(struct transcription_context *gf, const std::vector<float> pcm32f_data,
int vad_state, const DetectionResultWithText &result){};

namespace locaal {

Transcription::Transcription()
{
// Constructor implementation
gf = new transcription_context();
}

Transcription::~Transcription()
{
// Destructor implementation
delete gf;
}

void Transcription::setTranscriptionParams(const std::string &language)
Expand Down Expand Up @@ -41,15 +58,15 @@ void Transcription::setTranscriptionCallback(
void Transcription::startTranscription()
{
Logger::log(Logger::Level::INFO, "Starting transcription...");
// Implement the logic to start the transcription process
// This might involve starting a new thread, initializing audio capture, etc.
// start the transcription thread
start_whisper_thread_with_path(this->gf, "en", "silero_vad_model_file");
}

void Transcription::stopTranscription()
{
Logger::log(Logger::Level::INFO, "Stopping transcription...");
// Implement the logic to stop the transcription process
// This might involve stopping the transcription thread, cleaning up resources, etc.
shutdown_whisper_thread(this->gf);
}

void Transcription::processAudio(const std::vector<float> &audioData)
Expand Down
8 changes: 3 additions & 5 deletions src/modules/transcription/src/whisper-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,13 @@ void run_inference_and_callbacks(transcription_context *gf, uint64_t start_offse
}
}

void whisper_loop(void *data)
void whisper_loop(transcription_context *gf)
{
if (data == nullptr) {
Logger::log(Logger::Level::ERROR_LOG, "whisper_loop: data is null");
if (gf == nullptr) {
Logger::log(Logger::Level::ERROR_LOG, "whisper_loop: context is null");
return;
}

struct transcription_context *gf = static_cast<struct transcription_context *>(data);

Logger::log(gf->log_level, "Starting whisper thread");

vad_state current_vad_state = {false, now_ms(), 0, 0};
Expand Down

0 comments on commit e349b96

Please sign in to comment.