2012年3月27日 星期二

Speech Platform v11 -- 1

文字轉語音又弄了半天半,擔心x64平台,x86發展工具
1. 系統說明
    Windows 7 x64 作業系統
    VS2010 x86 工具
    ASUS A43S 筆電
2. Ref : http://www.microsoft.com/download/en/details.aspx?id=27224

Instructions


  • First install the Microsoft Speech Platform - Runtime 11.0
  • Click the file you want to download from the list below.
  • Do one of the following:
    • To start the installation immediately, click Open or Run this program from its current location.
    • To copy the download to your computer for installation at a later time, click Save or Save this program to disk
1. 下載 Speech Platform Runtime 安裝
2. 下載 MSSpeech_TTS_zh-TW_HanHan.msi 中文安裝
3. 下載 MSSpeech_SR_zh-TW_TELE 中文安裝
4. 下載SDK安裝
5. Console mode testing program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Add SpeechLib.DLL from COM component
using SpeechLib;

namespace Speech5
{
    class Program
    {
        static void Main(string[] args)
        {
            SpVoice 說 = new SpVoice();
            說.Speak("本專題運用DXStudio與VS 2010開發工具,建立視窗型的角色扮演應用程式,除整理DXStudio可運用的場景、人物、物件等元件,以DXStudio編輯器,自行規劃場景與加入人物,綜合運用javascript與C#程式,開發遊戲所需之程式模組");
            說.Speak("This is a test for English speaking.", SpeechVoiceSpeakFlags.SVSFDefault);
        }
    }
}
測試OK!

2012年3月18日 星期日

Workflow-(i)

Hello world for workflow:
1. There are four templates for workflow applications
2. Hello world : WorkflowConsoleApplication
Basic structure is almost same as C# console mode application
namespace/class/Main

namespace WorkflowConsoleApplication2
{

    class Program
    {
        static void Main(string[] args)
        {
            WorkflowInvoker.Invoke(new Workflow1());
        }
    }
}
One more file in the project
Workflow1.xaml
2-1 the graphic form 
2-2 tag form
2-3 說明:

主程式進入點,由Workflow1.xaml類別建置物件
 WorkflowInvoker.Invoke(new Workflow1()); 
Workflow1.xaml 類別可用圖形界面,建構活動

3. Workflow1.xaml 可以用C#建置
 static Activity wf = new Sequence()
        {
            Activities = {
                                new WriteLine()
                                {
                                   Text = "Before the 1 minute delay."
                                },
                                new Delay()
                                {
                                    Duration = TimeSpan.FromSeconds(20)
                                },
                                new WriteLine()
                                {
                                    Text = "After the 1 minute delay."
                                }
                              }
        };
        
        static void Main(string[] args)
        {
            WorkflowInvoker.Invoke(new Workflow1()); // Call WorkFlow1.xaml
            try
            {
                WorkflowInvoker.Invoke(wf, TimeSpan.FromSeconds(60)); // Based on static Activity to create.
            }
            catch (TimeoutException ex)
            {
                Console.WriteLine(ex.Message);
            }


        }




2012年3月1日 星期四

Convert Powerpoint to images

1. Add reference

// Add Microsoft.Office.Iterop.PowerPoint v 14.0.0.0 (@NET)
// Add Microsoft Office 14.0 Object Library (@COM)
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
2. Prepare myppt.pptx in debug or release folder
3. ConsoleMode program (Open vs2010 by administrator role)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Add Micorsoft.Office.Iterop.PowerPoint v 14.0.0.0
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ApplicationClass ppt = new ApplicationClass();
            Presentation pptPresentation = ppt.Presentations.Open(@"E:\Working\pptimage\ConsoleApplication1\ConsoleApplication1\bin\Debug\myppt.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            for (int i = 1; i <= pptPresentation.Slides.Count ; i++)
            {
                pptPresentation.Slides[i].Export(@"E:\Working\pptimage\ConsoleApplication1\ConsoleApplication1\bin\Debug\slide" + i.ToString() + ".jpg", "jpg", 320, 240);
            }
           
        }
    }
}

4. Change both of  properties in
    Microsoft.Office.Iterop.PowerPoint v 14.0.0.0 (@NET)
    Microsoft Office 14.0 Object Library (@COM)
    Embed Interop Type -> False


5. Note: 1. The default directory of Slides[].Export is My Document
              2. It seems not to work without excuted by administrator role.


2012年2月29日 星期三

WPF 3D - 1 : Rotating Sphere

1. Add Ref: Primitive3DSurfaces.DLL
2. Add
     xmlns:my="clr-namespace:Primitive3DSurfaces;assembly=Primitive3DSurfaces"
3.

<Grid>
        <Grid.Background>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                <LinearGradientBrush.GradientStops>
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="DarkBlue" Offset="1"/>
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </Grid.Background>
        <Viewport3D Grid.Column="0" Grid.Row="0">
            <Viewport3D.Camera>
                <PerspectiveCamera Position="0,0,-8" UpDirection="0,1,0" LookDirection="0,0,1" FieldOfView="45" NearPlaneDistance="0.125"/>
            </Viewport3D.Camera>
            <Viewport3D.Children>
                <ModelVisual3D>
                    <ModelVisual3D.Content>
                        <DirectionalLight Color="White" Direction="0,0,1" />
                    </ModelVisual3D.Content>
                </ModelVisual3D>
                <ModelVisual3D>
                    <ModelVisual3D.Transform>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D  x:Name="rotation" Angle="0" Axis="0,1,0" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </ModelVisual3D.Transform>
                    <my:Sphere3D>
                        <ModelVisual3D.Transform>
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"  />
                        </ModelVisual3D.Transform>
                        <my:Sphere3D.Material>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <ImageBrush ImageSource="earthspec1k.jpg" />
                                </DiffuseMaterial.Brush>

                            </DiffuseMaterial>
                        </my:Sphere3D.Material>
                    </my:Sphere3D>
                 
                </ModelVisual3D>
            </Viewport3D.Children>
        </Viewport3D>
    </Grid>
4. Add storyboard

<Window.Triggers>
    <EventTrigger RoutedEvent="Window.Loaded" >
      <BeginStoryboard>
        <Storyboard Name="myStoryBoard">
          <DoubleAnimation
            Storyboard.TargetName="rotation"
            Storyboard.TargetProperty="Angle"
            From="0" To="360" Duration="0:0:10" RepeatBehavior="Forever"/>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Window.Triggers>
5. 

5. VS2010CS範例下載


2012年2月28日 星期二

Kinect SDK V1.0 (1)

一時間看不來正式版SDK,測試入門語法。
ref: http://channel9.msdn.com/Series/KinectQuickstart/Camera-Fundamentals
1. 環境: SDK installed.
2. Open new WPF project.
3. Add Reference
     Microsoft.Kinect
     Microsoft.Samples.Kinect.WpfViewers"

4. Add using namespace Microsoft.Kinect
5. Add (@ Xaml file)
    xmlns:my="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers"
6. Add 2 xaml tags

 <my:KinectSensorChooser  Margin="234,104,0,0" Name="kinectSensorChooser1"  />
        <my:KinectColorViewer Width="640" Height="480" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}"></my:KinectColorViewer>
7. Add Window_Loaded event method
    kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
8. Copy  private void StopKinect(KinectSensor sensor) from refernce
     private void StopKinect(KinectSensor sensor)
        {
            if (sensor != null)
            {
                if (sensor.IsRunning)
                {
                    //stop sensor
                    sensor.Stop();

                    //stop audio if not null
                    if (sensor.AudioSource != null)
                    {
                        sensor.AudioSource.Stop();
                    }


                }
            }
        }
9. Add event method

void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var oldSensor = (KinectSensor)e.OldValue;
            //stop the old sensor
            if (oldSensor != null)
            {
                StopKinect(oldSensor);
            }
            //get the new sensor
            var newSensor = (KinectSensor)e.NewValue;
            if (newSensor == null)
            {
                return;
            }
            //newSensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(newSensor_AllFramesReady);
            //turn on features that you need
            newSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
            //newSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
            //newSensor.SkeletonStream.Enable();
            try
            {
                newSensor.Start();
            }
            catch (System.IO.IOException)
            {
                //this happens if another app is using the Kinect
                kinectSensorChooser1.AppConflictOccurred();
            }
        }


10. Add Window_Closing event method to close the kinect.


2012年2月24日 星期五

HTTP 錯誤 500.19 - Internal Server Error HTTP 錯誤 500.19 - Internal Server Error

1. VS2010 error

2. Install asp.net

3. Error
HTTP 錯誤 500.21 - Internal Server Error
若您是先安裝.NET Framework 4.0獨立安裝程式再啟用IIS角色就可能遇到上述的錯誤訊息,原因在於IIS角色在啟用時並未更新現有的應用程式以使用ASP.NET 4 版本的應用程式集區 ,以及在 IIS Metabase 中未更新傳統模式及 IIS 整合模式下ASP.NET 4的處理常式與指令對應,以至於出現上述的錯誤訊息。
4. Windows 7 x64












5. Done

2012年2月22日 星期三

WPF 命令列 2

1.  測試檔案
// FileName: App1.cs

class app
{
[System.STAThread]
static void Main()
{
 w1 w = new w1();
 w.ShowDialog();
}
}
class w1:System.Windows.Window
{

}
2. 編譯指令
csc  /out:App1.exe  /target:winexe   app1.cs /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\presentationframework.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\windowsbase.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\presentationcore.dll"
3. 結果