Skip to content

Commit

Permalink
Added sample code for RHVoiceObjC project
Browse files Browse the repository at this point in the history
  • Loading branch information
IhorShevchuk committed Mar 28, 2024
1 parent ac79735 commit ecc04d4
Show file tree
Hide file tree
Showing 15 changed files with 632 additions and 8 deletions.
14 changes: 14 additions & 0 deletions Samples/RHVoiceObjC/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Sample

This folder contains Sample of RHVoice usage on iOS and macOS apps

Main code is located in [ContentView.swift](Sample/ContentView.swift) file
Also please pay attention to [RHVoice.json](Sample/RHVoice.json) file and PackDataPlugin in Build Phases
Please find the full list of [Languages](https://github.com/RHVoice/RHVoice/tree/1.14.0/data/languages) and [Voices](https://github.com/RHVoice/RHVoice/tree/1.14.0/data/voices) by respective links.

## Build & Run Instruction

1. Open `Sample.xcodeproj`
1. Select destination
1. Fix signing issues if needed
1. Run
426 changes: 426 additions & 0 deletions Samples/RHVoiceObjC/Sample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
}
}
],
"version" : 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Samples/RHVoiceObjC/Sample/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
35 changes: 35 additions & 0 deletions Samples/RHVoiceObjC/Sample/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ContentView.swift
// Sample
//
// Created by Ihor Shevchuk on 28.03.2024.
//

import RHVoiceObjC
import SwiftUI

struct ContentView: View {

let synthesizer = RHSpeechSynthesizer()

var body: some View {
VStack {
Button {
let voice = RHSpeechSynthesisVoice.speechVoices().first

let utterance = RHSpeechUtterance(text: "Sample Text")
if let voice = voice {
utterance.voice = voice
}
synthesizer.speak(utterance)
} label: {
Text("Play Sample")
}
}
.padding()
}
}

#Preview {
ContentView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
8 changes: 8 additions & 0 deletions Samples/RHVoiceObjC/Sample/RHVoice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"languages":[
"English"
],
"voices":[
"alan"
]
}
10 changes: 10 additions & 0 deletions Samples/RHVoiceObjC/Sample/Sample.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
17 changes: 17 additions & 0 deletions Samples/RHVoiceObjC/Sample/SampleApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// SampleApp.swift
// Sample
//
// Created by Ihor Shevchuk on 28.03.2024.
//

import SwiftUI

@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
2 changes: 1 addition & 1 deletion Sources/Plugins/PackData/PackDataPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct PackDataPlugin: BuildToolPlugin {
let jsonData = try Data(contentsOf: inputURL)
let jsonInfo = try JSONDecoder().decode(JSONFormat.self, from: jsonData)

let inputDataFolder = packageRoot + "/RHVoice/data"
let inputDataFolder = packageRoot + "/RHVoice/RHVoice/data"

return [
.buildCommand(
Expand Down
13 changes: 6 additions & 7 deletions Sources/RHVoiceSwift/RHSpeechSynthesizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@ import AVFoundation
public class RHSpeechSynthesizer {
public struct Params {
// TODO: have logger protocol(RHVoiceLoggerProtocol) and add variable of it's type here
public var dataPath: String?
public var configPath: String?
public var dataPath: String
public var configPath: String
public static var `default`: Params = {
var pathToData = Bundle.main.path(forResource: "RHVoiceData", ofType: nil)
if pathToData == nil || pathToData?.isEmpty == true {
let rhVoiceBundle = Bundle(path: Bundle.main.path(forResource: "RHVoice_RHVoice", ofType: "bundle") ?? "")
pathToData = rhVoiceBundle?.path(forResource: "data", ofType: nil)
}
return Params(dataPath: pathToData,
// TODO: use FileManager.default.currentDirectoryPath here
configPath: "")
return Params(dataPath: pathToData ?? "",
configPath: FileManager.default.currentDirectoryPath + "/")

}()

var rhVoiceParam: RHVoice_init_params {
var result = RHVoice_init_params()
result.data_path = dataPath?.toPointer()
result.config_path = configPath?.toPointer()
result.data_path = dataPath.toPointer()
result.config_path = configPath.toPointer()
return result
}
}
Expand Down

0 comments on commit ecc04d4

Please sign in to comment.