0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

眺めて覚える C# Xamarin (6) 音声合成

Posted at

早い話がAndroidにしゃべらすプログラムです。

なるべくちょいちょいとやるためには、Nugetでプラグインをインストールします。

Step1

image.png

Step2

image.png

Step3

image.png

Step4

image.png

Step5

image.png

nugetの追加

image.png

image.png
Xam.Plugins.TextToSpeechの導入

MainPage.xaml.cs
using Plugin.TextToSpeech; //プラグインの導入
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Text2Speech
{

    [DesignTimeVisible(false)]
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            //ボタンの定義
            var btn = new Button() { Text = "話す",FontSize=48 };
            btn.Clicked += Btn_Clicked;
            Content = btn;
        }
        /// <summary>
        /// ボタンクリック時の動作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Clicked(object sender, EventArgs e)
        {
            //喋らせる
            CrossTextToSpeech.Current.Speak("ソシアル ディスタンス。\n2メートル以上離れてください。\nソシアル ディスタンス。\n2メートル以上離れてください。\n");
        }
    }
}

実行結果

後からエレベータに駆け込んだお兄さんがおりた!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?