Skip to content

Commit

Permalink
Added RHVoice as submodule and moved all the code needed to this repo…
Browse files Browse the repository at this point in the history
…sitory
  • Loading branch information
IhorShevchuk committed Feb 16, 2024
1 parent 619a2d2 commit fee2f33
Show file tree
Hide file tree
Showing 47 changed files with 2,012 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/buiild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build
on:
push:
branches:
- 'main'

jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: sersoft-gmbh/swifty-linux-action@v3
with:
release-version: 5.9.2
- run: |
rm -fr .build | echo "Removed build folder"
swift build -c release --target RHVoiceCore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
.swiftpm/xcode
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "RHVoice"]
path = RHVoice
url = https://github.com/RHVoice/RHVoice.git
23 changes: 23 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "boost.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/IhorShevchuk/Boost.swift.git",
"state" : {
"revision" : "8d94cd03fdd1731236da58b35ee54d329d8d42f5",
"version" : "1.80.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
}
}
],
"version" : 2
}
187 changes: 187 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// swift-tools-version: 5.7

// Copyright (C) 2022 Olga Yakovleva <olga@rhvoice.org>

import PackageDescription
import Foundation

let package = Package(
name: "RHVoice",
platforms: [
.macOS(.v11),
.iOS(.v13)
],
products: [
.library(
name: "RHVoice",
targets: ["RHVoice"]),
.plugin(name: "PackDataPlugin", targets: [
"PackDataPlugin"
])
],
dependencies: [
/// This is a forked repo of https://github.com/GigaBitcoin/Boost.swift
.package(url: "https://github.com/IhorShevchuk/Boost.swift.git", .upToNextMajor(from: "1.80.0")),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0")
],
targets: [
.target(
name: "RHVoiceCore",
dependencies: [
.product(name: "algorithm", package: "Boost.swift"),
.product(name: "array", package: "Boost.swift"),
.product(name: "assert", package: "Boost.swift"),
.product(name: "bind", package: "Boost.swift"),
.product(name: "concept_check", package: "Boost.swift"),
.product(name: "config", package: "Boost.swift"),
.product(name: "container", package: "Boost.swift"),
.product(name: "container_hash", package: "Boost.swift"),
.product(name: "core", package: "Boost.swift"),
.product(name: "date_time", package: "Boost.swift"),
.product(name: "detail", package: "Boost.swift"),
.product(name: "foreach", package: "Boost.swift"),
.product(name: "function", package: "Boost.swift"),
.product(name: "integer", package: "Boost.swift"),
.product(name: "io", package: "Boost.swift"),
.product(name: "iterator", package: "Boost.swift"),
.product(name: "lexical_cast", package: "Boost.swift"),
.product(name: "move", package: "Boost.swift"),
.product(name: "mpl", package: "Boost.swift"),
.product(name: "multi_index", package: "Boost.swift"),
.product(name: "numeric_conversion", package: "Boost.swift"),
.product(name: "optional", package: "Boost.swift"),
.product(name: "preprocessor", package: "Boost.swift"),
.product(name: "range", package: "Boost.swift"),
.product(name: "serialization", package: "Boost.swift"),
.product(name: "signals2", package: "Boost.swift"),
.product(name: "smart_ptr", package: "Boost.swift"),
.product(name: "static_assert", package: "Boost.swift"),
.product(name: "throw_exception", package: "Boost.swift"),
.product(name: "tokenizer", package: "Boost.swift"),
.product(name: "tuple", package: "Boost.swift"),
.product(name: "type_index", package: "Boost.swift"),
.product(name: "type_traits", package: "Boost.swift"),
.product(name: "utility", package: "Boost.swift"),
.product(name: "variant", package: "Boost.swift")
],
path: "RHVoice/src/",
exclude: [
// Files that are not compiled because they are included into sources directly
"core/unidata.cpp",
"core/userdict_parser.c",
"core/emoji_data.cpp",
// Platform audio files that shouldn't be compiled for iOS and macOS(at least in scope of this package)
"audio/libao.cpp",
"audio/portaudio.cpp",
"audio/pulse.cpp",
// cmake files
"core/CMakeLists.txt",
"hts_engine/CMakeLists.txt",
"audio/CMakeLists.txt",
"lib/CMakeLists.txt",
// Scons files
"audio/SConscript",
"core/SConscript",
"hts_engine/SConscript",
"lib/SConscript",
"pkg/SConscript",
// Not used on Apple platfroms since config path is set during runtime
"core/config.h.in",
// Not used on Apple platforms
"core/userdict_parser.g"
],
sources: [
"core",
"hts_engine",
"lib",
"audio"
],
publicHeadersPath: "include/",
cSettings: [
.headerSearchPath("include/**"),
.headerSearchPath("hts_engine"),
.headerSearchPath("third-party/utf8"),
.headerSearchPath("third-party/rapidxml"),
.headerSearchPath("../../Sources/Mock"),
.define("RHVOICE"),
.define("PACKAGE", to: "\"RHVoice\""),
.define("DATA_PATH", to: "\"\""),
.define("CONFIG_PATH", to: "\"\""),
.define("ANDROID"),
.define("TARGET_OS_IPHONE", .when(platforms: [.iOS])),
.define("TARGET_OS_MAC", .when(platforms: [.macOS]))
]
),
.target(name: "RHVoice",
dependencies: [
.target(name: "RHVoiceCore")
],
path: "Sources",
sources: [
"CoreLib",
"RHVoice",
"Utils"
],
publicHeadersPath: "RHVoice/PublicHeaders/",
cSettings: [
.headerSearchPath("../RHVoice/src/third-party/utf8"),
.headerSearchPath("../RHVoice/src/third-party/rapidxml"),
.headerSearchPath("RHVoice/Logger"),
.headerSearchPath("RHVoice/PrivateHeaders"),
.headerSearchPath("Utils"),
.headerSearchPath("CoreLib"),
.headerSearchPath("Mock"),
.define("ANDROID"),
.define("TARGET_OS_IPHONE", .when(platforms: [.iOS])),
.define("TARGET_OS_MAC", .when(platforms: [.macOS]))
],
linkerSettings: [
.linkedFramework("AVFAudio")
]
),
/// Plugin to copy languages and voices data files
.executableTarget(
name: "PackDataExecutable",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser")
],
path: "Sources/Plugins/PackDataExecutable"
),
.plugin(name: "PackDataPlugin",
capability: .buildTool(),
dependencies: [
.target(name: "PackDataExecutable")
],
path: "Sources/Plugins/PackData",
sources: [
"PackDataPlugin.swift"
]
)
],
cLanguageStandard: .c11,
cxxLanguageStandard: .cxx11
)

func versionString(fileName: String) -> String {
let defaultValue = "\"\""
do {
let packageURL = URL(fileURLWithPath: #file).deletingLastPathComponent()
let input = packageURL.appendingPathComponent(fileName)
let inputString = try String(contentsOf: input)
guard let begin = inputString.range(of: "next_version=") else {
return defaultValue
}

guard let end = inputString.range(of: "\n", range: begin.upperBound..<inputString.endIndex) else {
return defaultValue
}

return String(inputString[begin.upperBound..<end.lowerBound])
} catch {

}
return defaultValue
}

let version = versionString(fileName: "RHVoice/SConstruct")
package.targets.first?.cSettings?.append(.define("VERSION", to: "\(version)"))
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# RHVoice-spm
# RHVoice

[![Build](https://github.com/IhorShevchuk/RHVoice-spm/actions/workflows/buiild.yml/badge.svg)](https://github.com/IhorShevchuk/RHVoice-spm/actions/workflows/buiild.yml)

A free and open source speech synthesizer with support for a lot languages now available for Swift Package Manager

# Usage

Add package as dependecy to your project

```swift
.package(url: "https://github.com/IhorShevchuk/RHVoice-spm",
.upToNextMajor(from: "1.14.0")),
```
1 change: 1 addition & 0 deletions RHVoice
Submodule RHVoice added at d1d5fc
75 changes: 75 additions & 0 deletions Sources/CoreLib/RHVoiceWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// RHVoiceWrapper.cpp
//
//
// Created by Ihor Shevchuk on 01.02.2023.
//
// Copyright (C) 2022 Olga Yakovleva <olga@rhvoice.org>

#include <stdio.h>

#include "RHVoiceWrapper.h"

using namespace RHVoice;

audio_player::audio_player(const std::string& path)
{
if(!path.empty())
{
stream.set_backend(RHVoice::audio::backend_file);
stream.set_device(path);
}
}

bool audio_player::set_sample_rate(int sample_rate)
{
try
{
if(stream.is_open()&&(stream.get_sample_rate()!=sample_rate))
stream.close();
stream.set_sample_rate(sample_rate);
return true;
}
catch(...)
{
return false;
}
}

bool audio_player::set_buffer_size(unsigned int buffer_size)
{
try
{
if(stream.is_open()&&(stream.get_buffer_size()!=buffer_size))
stream.close();
stream.set_buffer_size(buffer_size);
return true;
}
catch(...)
{
return false;
}
}

bool audio_player::play_speech(const short* samples,std::size_t count)
{
try
{
if(!stream.is_open())
stream.open();
stream.write(samples,count);
return true;
}
catch(...)
{
stream.close();
return false;
}
}

void audio_player::finish()
{
if(stream.is_open())
stream.drain();
}

48 changes: 48 additions & 0 deletions Sources/CoreLib/RHVoiceWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright (C) 2012, 2013, 2018 Olga Yakovleva <yakovleva.o.v@gmail.com> */

/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 2 of the License, or */
/* (at your option) any later version. */

/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */

/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <https://www.gnu.org/licenses/>. */


#ifndef RHVoiceWrapper_h
#define RHVoiceWrapper_h

#include <memory>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <iterator>
#include <algorithm>

#include "core/engine.hpp"
#include "core/document.hpp"
#include "core/client.hpp"
#include "audio.hpp"

namespace RHVoice {

class audio_player: public RHVoice::client
{
public:
explicit audio_player(const std::string& path);
bool play_speech(const short* samples,std::size_t count);
void finish();
bool set_sample_rate(int sample_rate);
bool set_buffer_size(unsigned int buffer_size);

private:
RHVoice::audio::playback_stream stream;
};

}
#endif /* RHVoiceWrapper_h */
1 change: 1 addition & 0 deletions Sources/Mock/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions Sources/Mock/core/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit fee2f33

Please sign in to comment.