Renamed TimeSegment to TimeRange
This commit is contained in:
parent
8c1e24e9c8
commit
2be3751a4f
|
@ -119,7 +119,7 @@ set(SOURCE_FILES
|
||||||
src/ProgressBar.cpp
|
src/ProgressBar.cpp
|
||||||
src/logging.cpp
|
src/logging.cpp
|
||||||
src/Timed.cpp
|
src/Timed.cpp
|
||||||
src/TimeSegment.cpp
|
src/TimeRange.cpp
|
||||||
)
|
)
|
||||||
add_executable(rhubarb ${SOURCE_FILES})
|
add_executable(rhubarb ${SOURCE_FILES})
|
||||||
target_link_libraries(rhubarb ${Boost_LIBRARIES} cppFormat sphinxbase pocketSphinx)
|
target_link_libraries(rhubarb ${Boost_LIBRARIES} cppFormat sphinxbase pocketSphinx)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include "TimeRange.h"
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
TimeRange::TimeRange(centiseconds start, centiseconds end) :
|
||||||
|
start(start),
|
||||||
|
end(end)
|
||||||
|
{
|
||||||
|
if (start > end) throw std::invalid_argument("start must not be less than end.");
|
||||||
|
}
|
||||||
|
|
||||||
|
centiseconds TimeRange::getStart() const {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
centiseconds TimeRange::getEnd() const {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
centiseconds TimeRange::getLength() const {
|
||||||
|
return end - start;
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "centiseconds.h"
|
#include "centiseconds.h"
|
||||||
|
|
||||||
class TimeSegment {
|
class TimeRange {
|
||||||
public:
|
public:
|
||||||
TimeSegment(centiseconds start, centiseconds end);
|
TimeRange(centiseconds start, centiseconds end);
|
||||||
centiseconds getStart() const;
|
centiseconds getStart() const;
|
||||||
centiseconds getEnd() const;
|
centiseconds getEnd() const;
|
||||||
centiseconds getLength() const;
|
centiseconds getLength() const;
|
|
@ -1,18 +0,0 @@
|
||||||
#include "TimeSegment.h"
|
|
||||||
|
|
||||||
TimeSegment::TimeSegment(centiseconds start, centiseconds end) :
|
|
||||||
start(start),
|
|
||||||
end(end)
|
|
||||||
{}
|
|
||||||
|
|
||||||
centiseconds TimeSegment::getStart() const {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
centiseconds TimeSegment::getEnd() const {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
centiseconds TimeSegment::getLength() const {
|
|
||||||
return end - start;
|
|
||||||
}
|
|
|
@ -1,12 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <TimeSegment.h>
|
#include <TimeRange.h>
|
||||||
|
|
||||||
template<typename TValue>
|
template<typename TValue>
|
||||||
class Timed : public TimeSegment {
|
class Timed : public TimeRange {
|
||||||
public:
|
public:
|
||||||
Timed(centiseconds start, centiseconds end, TValue value) :
|
Timed(centiseconds start, centiseconds end, TValue value) :
|
||||||
TimeSegment(start, end),
|
TimeRange(start, end),
|
||||||
value(value)
|
value(value)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ float getRMS(AudioStream& audioStream, int maxSampleCount = numeric_limits<int>:
|
||||||
return sampleCount > 0 ? static_cast<float>(std::sqrt(sum / sampleCount)) : 0.0f;
|
return sampleCount > 0 ? static_cast<float>(std::sqrt(sum / sampleCount)) : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream) {
|
vector<TimeRange> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream) {
|
||||||
// Make sure audio stream has no DC offset
|
// Make sure audio stream has no DC offset
|
||||||
audioStream = removeDCOffset(std::move(audioStream));
|
audioStream = removeDCOffset(std::move(audioStream));
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream
|
||||||
float cutoff = rms / 50;
|
float cutoff = rms / 50;
|
||||||
centiseconds maxGap(10);
|
centiseconds maxGap(10);
|
||||||
|
|
||||||
vector<TimeSegment> result;
|
vector<TimeRange> result;
|
||||||
optional<centiseconds> segmentStart, segmentEnd;
|
optional<centiseconds> segmentStart, segmentEnd;
|
||||||
for (centiseconds time = centiseconds(0); !audioStream->endOfStream(); ++time) {
|
for (centiseconds time = centiseconds(0); !audioStream->endOfStream(); ++time) {
|
||||||
float currentPower = getRMS(*audioStream, sampleRate / 100);
|
float currentPower = getRMS(*audioStream, sampleRate / 100);
|
||||||
|
@ -41,14 +41,14 @@ vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream
|
||||||
}
|
}
|
||||||
segmentEnd = time + centiseconds(1);
|
segmentEnd = time + centiseconds(1);
|
||||||
} else if (segmentEnd && time > segmentEnd.value() + maxGap) {
|
} else if (segmentEnd && time > segmentEnd.value() + maxGap) {
|
||||||
result.push_back(TimeSegment(segmentStart.value(), segmentEnd.value()));
|
result.push_back(TimeRange(segmentStart.value(), segmentEnd.value()));
|
||||||
logTimedEvent("utterance", segmentStart.value(), segmentEnd.value(), "");
|
logTimedEvent("utterance", segmentStart.value(), segmentEnd.value(), "");
|
||||||
segmentStart.reset();
|
segmentStart.reset();
|
||||||
segmentEnd.reset();
|
segmentEnd.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (segmentEnd) {
|
if (segmentEnd) {
|
||||||
result.push_back(TimeSegment(segmentStart.value(), segmentEnd.value()));
|
result.push_back(TimeRange(segmentStart.value(), segmentEnd.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <TimeSegment.h>
|
#include <TimeRange.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "AudioStream.h"
|
#include "AudioStream.h"
|
||||||
|
|
||||||
std::vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream);
|
std::vector<TimeRange> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream);
|
||||||
|
|
Loading…
Reference in New Issue