看这段SDK中的VB例子:
Dim objVOICE As SpeechLib.SpVoice ***********
Dim objFSTRM As SpeechLib.SpFileStream ***********
Const strFName = "C:/AudioOutputStream.wav"
Private Sub Command1_Click()
'Build a local file path and open it as a stream
Call objFSTRM.Open(strFName, SSFMCreateForWrite, False) ***********
'Set voice AudioOutputStream to the stream and speak
Set objVOICE.AudioOutputStream = objFSTRM ***********
objVOICE.Speak Text1.Text
'Close the stream and set voice back to speaking
Call objFSTRM.Close
Set objVOICE.AudioOutputStream = Nothing
从上面***********的地方看出,objFSTRM 是直接赋值给objVOICE.audioOutputStream的,
但再delphi中直接赋值会出错,显示是incompatible type:'TSpFileStream' and 'ISpeechBaseStream',
这不就是说明类型不符吗?强制转换成其中的某个类型也不行。
语句如下:
var
filsStr:TspFileStream;
...
fileStr.Open('d:/out.wav',3,false);
spvoice1.AudioOutputStream := fileStr;
...
根据SDK说明档,有
AudioOutputStream Property
The AudioOutputStream property gets and sets the current audio stream object used by the voice.
Setting the voice's AudioOutputStream property may cause its audio output format to be automatically changed to match the text-to-speech (TTS) engine's preferred audio output format. If the voice's AllowAudioOutputFormatChangesOnNextSet property is True, the format change takes place; if False, the format remains unchanged. In order to set the AudioOutputStream property of a voice to a specific format, its AllowOutputFormatChangesOnNextSet should be False.
Syntax
Set: SpVoice.AudioOutputStream = ISpeechBaseStream
Get: ISpeechBaseStream = SpVoice.AudioOutputStream
Parts
SpVoice
The owning object.
ISpeechBaseStream
Get: An ISpeechBaseStream object that gets the current audio output stream.
Set: An ISpeechBaseStream object that sets the audio output stream.
但 ISpeechBaseStream的说明却是:
ISpeechBaseStream
The ISpeechBaseStream automation interface defines properties and methods for manipulating data streams.
ISpeechBaseStream objects normally contain audio data, but may also be used for text data.
The Read, Write and Seek methods maintain a pointer referred to as the Seek pointer. The Read and Write methods begin reading or writing at the Seek pointer, and reset the Seek pointer one byte past the last byte read or written. The Seek method returns the current pointer, and can also move the Seek pointer forward or backward in the stream, starting from the Seek pointer, or relative to the beginning or the end of the stream.
Use of the Read, Write and Seek methods are demonstrated in a code example at the end of the ISpeechBaseStream section.
The ISpeechBaseStream is not an object in its own right, but is implemented by other objects, such as SpFileStream and SpMemoryStream. SAPI does not call ISpeechBaseStream methods, but uses the underlying COM interfaces. For this reason, a custom object cannot be created using the ISpeechBaseStream interface.
Automation Interface Elements
The ISpeechBaseStream automation interface contains the following elements:
Properties Description
Format Property :Gets and sets the cached wave format of the stream as an SpAudioFormat object.
Methods Description
Read Method :Reads data from the audio stream.
Seek Method :Returns the current read position of the audio stream in bytes.
Write Method :Writes data to the audio stream
本来E语就不怎么样,现在是越看越晕了,谁知道这个AudioOutputStream在Delphi中怎么样用?