德尔福SAPI文字转语音
问题说明
首先:这不是 Delphi和SAPI 的重复。我在Delphi中的SAPI主题有一个具体的问题。
First of all: this is not a duplicate of Delphi and SAPI. I have a specific problem with the "SAPI in Delphi" subject.
我在Delphi 2009中使用了优秀的Import Type-Library指南,以获得组件中的TSpVoice组件调色板这很好。使用
I have used the excellent Import Type-Library guide in Delphi 2009 to get a TSpVoice component in the component palette. This works great. With
var
SpVoice: TSpVoice;
我可以写
SpVoice.Speak('This is an example.', 1);
获取异步音频输出。
第一个问题
First question
根据文档,我可以写
SpVoice.Speak('This is an example.', 0);
获取同步音频输出,而是得到一个EZeroDivide异常。为什么?
to get synchronous audio output, but instead I get an EZeroDivide exception. Why's that?
第二个问题
Second question
但是更重要的是,我想能够动态创建SpVoice对象(我认为这称为晚期绑定SpVoice对象),部分原因是我的应用程序的所有会话中只有很小一部分将使用它,部分原因是我不想假定在最终用户的系统上存在SAPI服务器。
But more importantly, I would like to be able to create the SpVoice object dynamically (I think this is called to "late-bind" the SpVoice object), partly because only a very small fraction of all sessions of my app will use it, and partly because I do not want to assume the existance of the SAPI server on the end-user's system.
为此,我尝试了
procedure TForm1.FormClick(Sender: TObject);
var
SpVoice: Variant;
begin
SpVoice := CreateOleObject('SAPI.SpVoice');
SpVoice.Speak('this is a test', 0);
end;
这显然什么都不做! (用1替换0给出了EZeroDivide异常。)
which apparently does nothing at all! (Replacing the 0 with 1 gives me the EZeroDivide exception.)
I am rather new to COM/OLE automation. I am sorry for any ignorance or stupidity shown by me in this post...
每个人遇到同样问题的好处,François解释说,SAPI / Windows中有一个错误(某些不兼容的地方),这使得以下代码提高了EZeroDivide异常:
For the benefit of everyone encountering the same problem as I did, the video by François explained there is a bug in SAPI/Windows (some incompatibility somewhere), which makes the following code raise the EZeroDivide exception:
procedure TForm1.FormClick(Sender: TObject);
var
SpVoice: variant;
begin
SpVoice := CreateOleObject('SAPI.SpVoice');
SpVoice.Speak('This is a text.');
end;
视频提供的解决方案是更改FPU控制字:
The solution, as presented by the video, is to alter the FPU control word:
procedure TForm1.FormClick(Sender: TObject);
var
SpVoice: variant;
SavedCW: Word;
begin
SpVoice := CreateOleObject('SAPI.SpVoice');
SavedCW := Get8087CW;
Set8087CW(SavedCW or $4);
SpVoice.Speak('This is a text.');
Set8087CW(SavedCW);
end;
此外,如果要异步播放声音,则必须确保玩家不会超出范围!
And, in addition, if you want to play a sound asynchronously, then you have to make sure that the player doesn't go out of scope!
正确答案
您可能会发现有趣的是看到这个CodeRage 4会话的会议.embarcadero.com/coderage/sessions =nofollow noreferrer>语音启用Delphi应用程序(zip)
你会得到你想要的how-to...
(我猜你在Vista或 上,零分差在XP上没有发生)
You may find interesting to see this CodeRage 4 session on "Speech Enabling Delphi Applications (zip)" You'll get the "how-to" you're looking for... (and I guess you are on Vista or as the the zero divide did not happend on XP)
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfhkbf
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20