-
-
Save dj1711572002/45308691b3bf304f25c39d2f9a238978 to your computer and use it in GitHub Desktop.
C# VisualStudio2019 VoiceSynthesis IMU(BNO055) Pithc Roll output Data toSpeech
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Voice Synthesis & Recognition on 2021/01/25 by T. Fujita | |
// 参照でSystem.Speechを追加すること | |
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using System.IO.Ports; | |
using System.Threading; | |
using System.IO; | |
using System.Speech; | |
using System.Speech.Synthesis; | |
using System.Globalization; | |
using System.Diagnostics; | |
using System.Reflection.Emit; | |
namespace STA23_VoiceSynthesis_rev01 | |
{ | |
public partial class Form1 : Form | |
{ | |
public static string text_1; | |
public static long ti; | |
public static int[] pit, pit_1, rol, rol_1;//生データ配列 | |
public static double[] pitma, rolma;//移動平均値配列 | |
public static int dpit, dpit_1, drol, drol_1,i,j,k,n; | |
public static int peakp, peakr; | |
public static long tip,tip_1, tir,tir_1; | |
public static int D_Box_x = 400; // ダイアログボックスの表示位置X | |
public static int D_Box_y = 100; // ダイアログボックスの表示位置Y | |
public static int Speech_flag = 0; // 0: 日本語用、1: 英語用 | |
//Speech 生成 | |
SpeechSynthesizer synth = new SpeechSynthesizer(); | |
// Stopwatchクラス生成 | |
Stopwatch sw = new System.Diagnostics.Stopwatch(); | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
public void button1_Click(object sender, EventArgs e) | |
{ | |
Debug.Print("Button1 CLICKED"); | |
serialPort1.ReadBufferSize = 8; | |
serialPort1.BaudRate = 115200; | |
serialPort1.Parity = Parity.None; | |
serialPort1.DataBits = 8; | |
serialPort1.StopBits = StopBits.One; | |
serialPort1.Handshake = Handshake.None; | |
serialPort1.PortName = portComboBox.Text; | |
Debug.Print("OPEN PortName=" + serialPort1.PortName); | |
serialPort1.Open(); | |
// Dialog_Synthesis dialog1 = new Dialog_Synthesis(); | |
// dialog1.Show(); | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
Application.Exit(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
string[] ports = SerialPort.GetPortNames(); | |
foreach (string port in ports) | |
{ | |
portComboBox.Items.Add(port); | |
} | |
if (portComboBox.Items.Count > 0) | |
{ portComboBox.SelectedIndex = 0; } | |
pit = new int[5]; | |
rol = new int[5]; | |
pitma = new double[5]; | |
rolma = new double[5]; | |
sw.Reset(); | |
sw.Start(); | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
string st = textBox1.Text; | |
synth.Speak(st); // 音声を同期で生成 | |
} | |
delegate void DataDelegate(string sdata); | |
private void printdata(string text) | |
{ | |
synth.Rate = 4;//話す速度 Max 10 | |
n++; | |
Debug.Print(text); | |
string[] st = text.Split(','); | |
int pitch = Convert.ToInt32(st[0]); | |
int roll= Convert.ToInt32(st[1]); | |
sw.Stop(); | |
tip = sw.ElapsedMilliseconds; | |
sw.Start(); | |
if ( tip - tip_1 > 4000) | |
{ | |
richTextBox1.ScrollToCaret(); | |
richTextBox1.AppendText("発声pitch=" + pitch.ToString()+",roll="+roll.ToString() + "time=" +(tip-tip_1).ToString()+"\r\n"); | |
synth.Speak("ピッチ" + pitch.ToString() + "ど"); // 音声を同期で生成 | |
Debug.Print("ロール発声=" + rol.ToString() + "tir=" + tir.ToString()); | |
synth.Speak("ロール" + roll.ToString() + "ど"); // 音声を同期で生成 | |
tip_1 = tip; | |
} | |
} | |
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) | |
{ | |
// string st = e.KeyChar + "がおされました"; | |
// synth.Speak(st); | |
} | |
// -------------------Serial受信部-------------------------------------------------- | |
private void serialPort1_DataReceived_1(object sender, SerialDataReceivedEventArgs e) | |
{ | |
Debug.Print("DataRecieved="); | |
string str = serialPort1.ReadLine(); | |
DataDelegate a = new DataDelegate(printdata); | |
BeginInvoke(a, str); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment