[Mono-osx] P/invoking the OS X speech API?

kangaroo grompf at sublimeintervention.com
Wed Feb 22 00:51:25 EST 2006


Nolan,

   It appears your problem is misunderstanding the C code (at least  
from my quick glance);

SpeechChannel is a pointer to SpeechChannelRecord; meaning that the  
SpeechChannel* expected in NewSpeechChannel is in fact a  
SpeechChannelRecord** which you have collapsed to the structure.

I'm also concerned about where the popuplation of the SpeechChannel  
is happening; I assume it is happening in native land in which case  
you probably want to use IntPtr and just pass the IntPtr around as  
needed rather than dealing with the structure.  There is no point in  
bringing in that data if you dont need to.

-kangaroo

On 21-Feb-06, at 11:05 PM, Nolan Darilek wrote:

> using System;
> using System.Runtime.InteropServices;
>
> namespace Meridian.Tts.Osx {
>
> 	[StructLayout(LayoutKind.Sequential)]
> 	struct SpeechChannel {
> 		[MarshalAs(UnmanagedType.ByValArray, SizeConst=1)]
> 				long[] data;
> 	}
>
> 	public class Channel {
>
> 		private SpeechChannel _id;
>
> 		protected const string _applicationServicesPath = "/System/ 
> Library/Frameworks/ApplicationServices.framework/Versions/Current/ 
> ApplicationServices";
>
> 		[DllImport(_applicationServicesPath)]
> 		private static extern short NewSpeechChannel(IntPtr voice, ref  
> SpeechChannel channel);
>
> 		[DllImport(_applicationServicesPath)]
> 		private static extern short SpeakText(SpeechChannel channel,  
> String text, long length);
>
> 	public Channel() {
> 	short rc = NewSpeechChannel((IntPtr)null, ref _id);
> 		Console.WriteLine(rc);
> 		Speak("Hello, world.");
> 	}
>
> 	public bool Speak(String text) {
> 		short rc = SpeakText(_id, text, (long)text.Length);
> 		return (rc == 0);
> 	}
>
> 	}
> }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20060222/7b409e33/attachment-0001.html


More information about the Mono-osx mailing list