Using SAPI with nAnt

I’ve been successfully using Microsoft’s Speech API (SAPI) in Visual Studio 2005 to create samples to demonstrate how we can harness text-to-speech capabilities. However, to get this to work with nAnt I had to be able to reference the Microsoft Speech COM component in the <references> section in a nAnt build file.

When you add a reference to the SpeechLib, Visual Studio builds an Interop dll to help you use the COM library in .NET applications. This Interop.SpeechLib.dll will be found in the bin/Debug folder of your project.

In order for nAnt to be able to find this, I added a line to the Post-build event command line dialog in the Properties page for the project.

copy $(TargetDir)binDebugInterop.SpeechLib.dll c:yourdestinationpath

Then in the build include file (.binc files) I added a reference to this DLL. We’ve got a collection of 3rd party libraries we use, so it went in that binc file.

<property name="SpeechLib" value="${ThirdParty.dir}microsoftInterop.SpeechLib.dll">

where ${ThirdParty.dir} is a property set elsewhere to point to the directory.

Then in the build file you simply add the following to the <references> section:

<include name="${SpeechLib}"/>

This will result in your buildfile now being able to reference a COM component from a nAnt build script using Interop. Happy SAPI!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.