我怎样才能让TTS将文件写入我的应用程序的目录?我的、应用程序、文件、目录

2023-09-06 05:34:54 作者:抱抱我.

我想从TextToSpeech引擎我的应用程序的缓存目录写入输出。为了为TTS在那里写我首先必须给它的权限这样做。但我不知道怎么办。据我所知,通常这样的问题都可以通过递的FileDescriptor 结束从而给的权限访问一个特定的文件来解决。但我不能做到这一点与TTS,作为TextToSpeech.synthesizeToFile方法只接受文件路径作为字符串,没有的FileDescriptor 。那么怎么办?

为使我的观点是TTS还真没有权限写入我的应用程序的目录,这里的code ...:

  TextToSpeech MTTS =新新TextToSpeech(背景下,这一点);
mTts.synthesizeToFile(文字,空,getCacheDir()+/+speech.wav);
 

和调试日志:

  08-20 14:46:11.257:ERROR / TtsService(336):无法创建
/data/data/com.myorg.myapp/cache/speech.wav由于异常java.io.IOException异常:权限被拒绝
 
电商宝贝图片下载工具 各类主图下载工具 1.3 最新版

解决方案

TextToSpeech.synthesizeToFile()在实际设备不工作。它只能在AVDS。

我一直在尝试这也同时使用原来的碧TTS引擎和第三方TTS引擎,试图写入无论是SD卡或内部存储器(一个根深蒂固的设备上):

  context.getDir(soundfiles,Context.MODE_WORLD_WRITEABLE);
 

但是,正如你提到的,该方法返回 TextToSpeech.SUCCESS ,而不实际创建文件。

如果您必须录制自己的语音合成输出为WAV文件,连接耳机输出至AUX输入的声卡在您的PC和使用任何录音软件来捕捉。

I want to write output from the TextToSpeech engine to my app's cache directory. In order to for the TTS to write there I first have to give it permissions to do so. But I don't know how. I understand that normally such problems can be solved by handing a FileDescriptor over thus giving permissions to access a specific file. But I can't do that with TTS, as the TextToSpeech.synthesizeToFile method only accepts the file path as a String, no FileDescriptor. So what to do?

To make my point that TTS really hasn't permissions to write to my app's directories, here's the code...:

TextToSpeech mTts = new new TextToSpeech(context, this);
mTts.synthesizeToFile(text, null, getCacheDir() + "/" + "speech.wav");

And the debugger log:

08-20 14:46:11.257: ERROR/TtsService(336): Can't create
/data/data/com.myorg.myapp/cache/speech.wav due to exception java.io.IOException: Permission denied

解决方案

TextToSpeech.synthesizeToFile() doesn't work in real devices. It only works in AVDs.

I have been experimenting with this, too, using both the original Pico TTS engine and a third party TTS engine, trying to write to either the sdcard or the internal memory (on a rooted device):

context.getDir("soundfiles", Context.MODE_WORLD_WRITEABLE);

But, as you noted, the method returns TextToSpeech.SUCCESS without actually creating the file.

If you must record your TTS output to a WAV file, connect the headset output to the aux input in a sound card in your PC and use any recording software to capture that.