k2-fsa / sherpa-onnx

Speech-to-text, text-to-speech, and speaker recognition using next-gen Kaldi with onnxruntime without Internet connection. Support embedded systems, Android, iOS, Raspberry Pi, RISC-V, x86_64 servers, websocket server/client, C/C++, Python, Kotlin, C#, Go, NodeJS, Java, Swift, Dart, JavaScript, Flutter
https://k2-fsa.github.io/sherpa/onnx/index.html
Apache License 2.0
2.44k stars 280 forks source link

Error while clicking Generate on IOS-SwiftUI TTS #832

Open hafsalm opened 2 months ago

hafsalm commented 2 months ago

Hi,

I'm getting the following error while clicking the generate button. I see the issue with getTtsFor_en_US_amy_low and working fine with getTtsForVCTK

I would greatly appreciate it if you could provide me with a solution to fix this problem.

image

I followed this https://k2-fsa.github.io/sherpa/onnx/ios/build-sherpa-onnx-swift.html

csukuangfj commented 2 months ago

Please show the output of

git diff

and post the screenshot of your xcode project files so that we can see what files you have added to the project.

hafsalm commented 2 months ago

Here is the output of git diff. I haven't made any change in the code. Just added the "en_US-amy-low" files to the project.

diff --git a/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj b/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj
index e9ea2c2..2d16d63 100644
--- a/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj
+++ b/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj
@@ -7,6 +7,364 @@
        objects = {

 /* Begin PBXBuildFile section */
+               0C6857772BE75995002A7AC6 /* en_US-amy-low.onnx in Resources */ = {isa = PBXBuildFile; fileRef = 0C6855EB2BE75995002A7AC6 /* en_US-amy-low.onnx */; };
------ SKIPPED FOR READABLITLY ---------
sourceTree = "<group>"; };
+               0C6857712BE75995002A7AC6 /* vi_dict */ = {isa = PBXFileReference; lastKnownFileType = file; path = vi_dict; sourceTree = "<group>"; };
+               0C6857722BE75995002A7AC6 /* yue_dict */ = {isa = PBXFileReference; lastKnownFileType = file; path = yue_dict; sourceTree = "<group>"; };
+               0C6857752BE75995002A7AC6 /* tokens.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tokens.txt; path = "../../../vits-piper-en_US-amy-low/tokens.txt"; sourceTree = "<group>"; };
+               0C6857762BE75995002A7AC6 /* en_US-amy-low.onnx.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "en_US-amy-low.onnx.json"; path = "../../../vits-piper-en_US-amy-low/en_US-amy-low.onnx.json"; sourceTree = "<group>"; };
                C917B4E12B0EEF3B005245AC /* SherpaOnnxTts.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SherpaOnnxTts.app; sourceTree = BUILT_PRODUCTS_DIR; };
                C917B4E42B0EEF3B005245AC /* SherpaOnnxTtsApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxTtsApp.swift; sourceTree = "<group>"; };
                C917B4E62B0EEF3B005245AC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -42,9 +758,664 @@
 /* End PBXFrameworksBuildPhase section */

 /* Begin PBXGroup section */
+               0C6855EF2BE75995002A7AC6 /* aav */ = {
+                       isa = PBXGroup;
+                       children = (
+                               0C6855EC2BE75995002A7AC6 /* vi */,
+                               0C6856FA2BE75995002A7AC6 /* zac */,
+                       );
+                       path = "!v";
+                       sourceTree = "<group>";
+               };
+               0C6856FC2BE75995002A7AC6 /* voices */ = {
+                       isa = PBXGroup;
+                       children = (
+                               0C6856FB2BE75995002A7AC6 /* !v */,
+                       );
+                       path = voices;
+                       sourceTree = "<group>";
+               };
+               0C6857732BE75995002A7AC6 /* espeak-ng-data */ = {
+                       isa = PBXGroup;
+                       children = (
+                               0C6856922BE75995002A7AC6 /* lang */,
+                               0C6857722BE75995002A7AC6 /* yue_dict */,
+                       );
+                       name = "espeak-ng-data";
+                       path = "../../../vits-piper-en_US-amy-low/espeak-ng-data";
+                       sourceTree = "<group>";
+               };
                C917B4D82B0EEF3B005245AC = {
                        isa = PBXGroup;
                        children = (
+                               0C6855EB2BE75995002A7AC6 /* en_US-amy-low.onnx */,
                                C9FE9FE82B0F3754009F1003 /* Frameworks */,
@@ -147,8 +1518,366 @@
                        isa = PBXResourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               0C6858BE2BE75996002A7AC6 /* qu_dict in Resources */,
+                               0C6858982BE75996002A7AC6 /* kk_dict in Resources */,
+                               0C6857F22BE75995002A7AC6 /* bs in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -291,6 +2020,7 @@
                                CODE_SIGN_STYLE = Automatic;
                                CURRENT_PROJECT_VERSION = 1;
                                DEVELOPMENT_ASSET_PATHS = "\"SherpaOnnxTts/Preview Content\"";
+                               DEVELOPMENT_TEAM = QSSSXUTZ8W;
                                ENABLE_PREVIEWS = YES;
                                FRAMEWORK_SEARCH_PATHS = "${PROJECT_DIR}/../../build-ios";
                                GENERATE_INFOPLIST_FILE = YES;
@@ -306,7 +2036,7 @@
                                );
                                MARKETING_VERSION = 1.0;
                                OTHER_LDFLAGS = "-lc++";
-                               PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxTts";
+                               PRODUCT_BUNDLE_IDENTIFIER = com.test.SherpaOnnxTts;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                                SWIFT_EMIT_LOC_STRINGS = YES;
                                SWIFT_OBJC_BRIDGING_HEADER = "${PROJECT_DIR}/../../swift-api-examples/SherpaOnnx-Bridging-Header.h";
@@ -323,6 +2053,7 @@
                                CODE_SIGN_STYLE = Automatic;
                                CURRENT_PROJECT_VERSION = 1;
                                DEVELOPMENT_ASSET_PATHS = "\"SherpaOnnxTts/Preview Content\"";
+                               DEVELOPMENT_TEAM = QSSSXUTZ8W;
                                ENABLE_PREVIEWS = YES;
                                FRAMEWORK_SEARCH_PATHS = "${PROJECT_DIR}/../../build-ios";
                                GENERATE_INFOPLIST_FILE = YES;
@@ -338,7 +2069,7 @@
                                );
                                MARKETING_VERSION = 1.0;
                                OTHER_LDFLAGS = "-lc++";
-                               PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxTts";
+                               PRODUCT_BUNDLE_IDENTIFIER = com.test.SherpaOnnxTts;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                                SWIFT_EMIT_LOC_STRINGS = YES;
                                SWIFT_OBJC_BRIDGING_HEADER = "${PROJECT_DIR}/../../swift-api-examples/SherpaOnnx-Bridging-Header.h";

Here is the xCode project files SS image

Thank you so much for your help.

csukuangfj commented 2 months ago

Could you describe how you added espeak-ng-data? Make.sure it is not a symlink.

Could you delete it and add it again?

Check that the reported file.in.the.error log does exist.

hafsalm commented 2 months ago

Here is how i added espeak-ng-data to the project.

  1. Downloaded the model file vits-piper-en_US-amy-low.tar.bz2 from https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models
  2. After extraction, from xCode, used the option Add files to 'SherpaOnnxTts' by selecting en_US-amy-low.onnx, en_US-amy-low.onnx.json, tokens.txt and espeak-ng-data folder.

When I check the espeak-ng-data folder, I'm able to see the 'phontab' file inside.

I also tried deleting espeak-ng-data folder reference from xcode and added again. Still the same issue.

Am I taking the right approach to adding the espeak-ng-data folder?

csukuangfj commented 2 months ago

Could.you use

ls -lh to check the file in the error.log.

Remember to copy and paste the absolute path from.the.error.log.

hafsalm commented 2 months ago

I checked for the file in the log '/private/var/containers/Bundle/Application/32C03D12-4D6E-4296-9192-F7452BBD0A7B/SherpaOnnxTts.app/espeak-ng-data/phontab' does not exist. when I ls -lh the full path, its showing error as No such file or directory.

I also tried removing the espeak-ng-data reference from xcode by deleting it. Still the same error. So I am assuming, the folder reference is not properly added with my steps. Can you pls tell me what is the right approach to adding the espeak-ng-data to the xcode? or something else I'm missing here?

I also tried by downloading the espeak-ng-data directly from https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/espeak-ng-data.tar.bz2.

csukuangfj commented 2 months ago

Pleasr check the paths in your git diff output.

The../../../ relative path looks suspicious.

csukuangfj commented 2 months ago

Pleasr check the paths in your git diff output.

The../../../ relative path looks suspicious.

hafsalm commented 1 month ago

The../../../ relative path looks suspicious.

the vits-piper-en_US-amy-low folder is outside the sherpa-onnx and from that location only the en_US-amy-low.onnx file being loaded.

Can you please advise me what is the right way of adding the en_US-amy-low.onnx and its supporting files including the espeak-ng-data folder?

i followed https://www.youtube.com/watch?v=MvePdkuMNJk for getTtsForVCTK and its working perfectly.

wujingcheng7 commented 1 month ago

I also encountered the same issue, but fortunately, I found the cause and fixed it. The crash here is caused by a null pointer, SherpaOnnxOfflineTtsWrapper.tts == nil, which is due to an incorrect configuration file passed during initialization. It seems that when you added files to the project, you selected "Create groups" in Xcode, which flattened the directory structure. The framework expects to access the directory /demo.app//espeak-ng-data/{target}, but the actual produced directory is /demo.app//{target}. This mismatch caused an error when passing /demo.app//espeak-ng-data as an argument to generate SherpaOnnxOfflineTtsVitsModelConfig, ultimately resulting in SherpaOnnxOfflineTtsWrapper.tts == nil.

My suggestion is to choose "Create folder references" when adding files and to check each path in func createOfflineTts() to ensure they are correct (you can directly call "FileManager.default.fileExists(atPath: path)"). If all paths are correct, the issue should be resolved.

Additionally, be cautious when using the two official demo methods func resourceURL(to path: String) -> String and func getResource( forResource: String, ofType: String) as they can be conflicting in some cases, where one expects correct input and the other expects incorrect input. You likely encountered this scenario. You should adapt these methods to fit your specific needs by obtaining the correct target path. You can refer to my modifications for guidance.

我也遇到了相同的问题,幸运的是我找到了原因并且修复了它。首先你这里崩溃的原因是空指针导致的,SherpaOnnxOfflineTtsWrapper.tts == nil,这是由于在它在 init 时传入的配置文件有误。你应该是在 add files to project 的时候选择了 “Create groups”,这会导致 XCode 完全打平目录,framework 希望访问的目录是 /demo.app//espeak-ng-data/{target} 但是实际生产的目录是 /demo.app//{target},这就导致当你把 /demo.app//espeak-ng-data 作为传入参数交给 framework 用于生成 SherpaOnnxOfflineTtsVitsModelConfig 时遭遇了错误,并最终导致 SherpaOnnxOfflineTtsWrapper.tts == nil。 所以我的建议是在你 add files 时选择 "Create folder references",并且在func createOfflineTts() 里面检查一下每个 path 是否正确(可以直接调用 "FileManager.default.fileExists(atPath: path)"),如果 path 都是正确的,那么问题就解决了。 此外,需要谨慎使用官方demo 的这两个方法 func resourceURL(to path: String) -> String 和 func getResource( forResource: String, ofType: String) -> String,在某些情况下这两个方法是互相矛盾的,也就是一个预期正确一个预期错误,你大概率就是遇到了这种情况。你需要结合你自己的实际情况,自己去获取争取的目标 path。这里你可以参考一下我的修改。

image