예제 #1
0
 private void DisposeNativeResource()
 {
     NativeResourceWrapper.CallNative((buffer) =>
     {
         int bufferSize = NativeResourceWrapper.BufferSize;
         var result     = this.NativeDelete(this.Native, buffer, ref bufferSize);
         NativeResourceWrapper.BufferSize = bufferSize;
         return(result);
     });
     this.Native = IntPtr.Zero;
 }
예제 #2
0
        /// <summary>
        /// Instantiate the native resource wrapped.
        /// </summary>
        /// <param name="args">The parameter is not used.</param>
        /// <returns>A pointer to the native resource.</returns>
        protected override IntPtr CreateNativeResources(params object[] args)
        {
            IntPtr native = IntPtr.Zero;

            NativeResourceWrapper.CallNative((buffer) =>
            {
                int bufferSize = NativeResourceWrapper.BufferSize;
                var result     = EnPronouncer_Create(out native, buffer, ref bufferSize);
                NativeResourceWrapper.BufferSize = bufferSize;
                return(result);
            });
            return(native);
        }
예제 #3
0
        /// <summary>
        /// Constructs a <see cref="EnPronunciation"/> from an ARPABET string array. E.g. (phonetic) ["F","AH","N","EH","T","IH","K"].
        /// </summary>
        /// <param name="arpabet">The ARPABET array.</param>
        /// <returns>The English pronunciation.</returns>
        public static EnPronunciation FromArpabet(IList <string> arpabet)
        {
            IntPtr native = IntPtr.Zero;

            NativeResourceWrapper.CallNative((buffer) =>
            {
                int bufferSize = NativeResourceWrapper.BufferSize;
                var result     = EnPronunciation_FromArpabet(arpabet.ToArray(), arpabet.Count, out native, buffer, ref bufferSize);
                NativeResourceWrapper.BufferSize = bufferSize;
                return(result);
            });

            return(new EnPronunciation(native));
        }
예제 #4
0
        /// <summary>
        /// Constructs a <see cref="EnPronunciation"/> from an IPA string. E.g. (phonetic) "fənɛtɪk".
        /// </summary>
        /// <param name="ipa">The IPA string.</param>
        /// <returns>The English pronunciation.</returns>
        public static EnPronunciation FromIpa(string ipa)
        {
            var    utf8 = Encoding.UTF8.GetBytes(ipa);
            IntPtr nativePronunciation = IntPtr.Zero;

            NativeResourceWrapper.CallNative((buffer) =>
            {
                int bufferSize = NativeResourceWrapper.BufferSize;
                var result     = EnPronunciation_FromIpa(utf8, out nativePronunciation, buffer, ref bufferSize);
                NativeResourceWrapper.BufferSize = bufferSize;
                return(result);
            });
            return(new EnPronunciation(nativePronunciation));
        }
예제 #5
0
        /// <summary>
        /// Pronounce text.
        /// </summary>
        /// <param name="phrase">The text to pronounce.</param>
        /// <returns>The English Pronunciation.</returns>
        public EnPronunciation Pronounce(string phrase)
        {
            if (phrase == null)
            {
                throw new ArgumentNullException("phrase can't be null");
            }

            IntPtr nativePronunciation = IntPtr.Zero;

            NativeResourceWrapper.CallNative((buffer) =>
            {
                int bufferSize = NativeResourceWrapper.BufferSize;
                var result     = EnPronouncer_Pronounce(this.Native, phrase, out nativePronunciation, buffer, ref bufferSize);
                NativeResourceWrapper.BufferSize = bufferSize;
                return(result);
            });

            return(new EnPronunciation(nativePronunciation));
        }