Ajaxでjsonファイルの値を取得

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->
</head>
<body>
  

  <button type="button" id="btn_display">表示</button>
  <article class="list">
    <div class="mes">京都の集合場所は<span class="pos"></span>、集合時間は<span class="time"></span>です。</div>
    <div class="mes">大阪の集合場所は<span class="pos"></span>、集合時間は<span class="time"></span>です。</div>
    <div class="mes">神戸の集合場所は<span class="pos"></span>、集合時間は<span class="time"></span>です。</div>
  </article>
	<script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>
  	<script>
      let optval;
      $(function(){
        $('.list').css("display", "none");
        $('#btn_display').on("click",function(){
            $.post({
               url: 'ajax_getLists.php',
            }).done(function(datas){
              $('.list').css("display", "block");

              var i = 0;
              $.each(datas, function(key, item){
                $(".pos").eq(i).text(item.position);
                $(".time").eq(i).text(item.ap_time);
                i++;
              })
            }).fail(function(XMLHttpRequest, textStatus, errorThrown){
              alert(errorThrown);
            })
        })
      })
  	</script>
</body>
</html>

$.postだけで全部取得できるのね。OK、使いやすそうです。

Ajaxで指定した変数の値をjsonファイルから取得する

html&jquery

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->
</head>
<body>
  <select id="sel">
      <option> --場所を選ぶ-- </option>
      <option value="kyoto">京都</option>
      <option value="osaka">大阪</option>
      <option value="kobe">神戸</option>
  </select>

  <div id="mes">
    集合場所は<span id="pos"></span>
    集合時刻は<span id="time"></span>
  </div>
	<script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>
  	<script>
      let optval;
      $(function(){
        $('#sel').on("change",function(){
            optval = $(this).val();
            $.post({
               url: 'ajax_getData.php',
               data: {
                  'opt': optval
               },
               dataType: 'json',
            }).done(function(data){
              $("#pos").text(data.position);
              $("#time").text(data.ap_time);
            }).fail(function(XMLHttpRequest, textStatus, errorThrown){
              alert(errorThrown);
            })
        })
      })
  	</script>
</body>
</html>

ajax_getData.php

header("Content-Type: application/json; charset=UTF-8");
$ary_sel_obj = [];
$opt = filter_input(INPUT_POST, "opt");

$ary_lists = [
	"kyoto" => [
		"position" => "三条",
		"ap_time" => "12:00",
	],
	"osaka" => [
		"position" => "難波",
		"ap_time" => "12:30",
	],
	"kobe" => [
		"position" => "西宮",
		"ap_time" => "13:00",
	],
];

if(isset($ary_lists)) $ary_sel_obj = $ary_lists[$opt];
echo json_encode($ary_sel_obj);
exit;

jsonデータが変わった時の処理としては、js側でデータを保持しておいて、jsonデータが変わったら、値を変えれば良さそう
うん、ある程度イメージは出来てきたかな🥰

jQueryで流れる文字

html & js

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
	<div id="flowing-text">
		<h2>Flowing Text</h2>
		<div class="fix-box">
			<div class="flowing-box">
				<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
			</div>
		</div>
	</div>
	<script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>
  	<script>
  		$(function(){
  			var $flowText = $('#flowing-text'),         
        		$fixBox = $flowText.find('.fix-box'),
        		$flowBox = $fixBox.find('.flowing-box'),

  				flowbox_width = $flowBox.width(),
  				flowTime=30000,
  				easing = 'linear',
  				right_start,
  				right_running,
  				timer;

    $flowBox.css({left:'100%'});
    right_start = $flowBox.offset().left+flowbox_width;

    function flowingStart (){
        if(!$flowBox.hasClass('stop')){ 
            $flowBox.animate(
                {left: -flowbox_width}, 
                flowTime, 
                easing,
                function(){     
                    $flowBox.css({left: '100%'});
                }
            );
            flowTime=30000;
        } else {    
            $flowBox.stop(true, false);
            right_running=$flowBox.offset().left+flowbox_width;
            flowTime=Math.floor(((right_running)/right_start)*10000);
        }
    }

    function flowingMonitor(){
        timer = setInterval(function(){
            flowingStart();
        },300);
    }

    $fixBox.on('mouseover',function(){
        $flowBox.addClass('stop');
    })
    .on('mouseout',function(){
        $flowBox.removeClass('stop');
    })
    
    flowingMonitor();

});
  	</script>
</body>
</html>
#flowing-text {
	margin:100px;
}
h2 {
	text-align:center;
	margin-bottom: 20px;
}
.fix-box {
	position: relative;
	height: 35px;
	box-shadow: 0px 0px 8px 3px #ccc inset;
	overflow: hidden;
}
.flowing-box {
	position: absolute;
	top: 5px;
	transform: translateY(-50%);
}
p {
	white-space: pre;
}

OK 大体のイメージは掴めた
テキストをajaxでPOST&GETで取得して表示できるようにしたい

[音声認識] DeepSpeechで中国語の音声認識を行う

まず中国語の音声ファイルを用意します

続いてDeepspeechの中国語モデルをDLします。
deepspeech-0.9.3-models-zh-CN.pbmm
deepspeech-0.9.3-models-zh-CN.scorer

実行は、Englishと同様
$ source deepspeech-venv/bin/activate
$ deepspeech –model deepspeech-0.9.3-models-zh-CN.pbmm –scorer deepspeech-0.9.3-models-zh-CN.scorer –audio audio/zh_test.wav
Loading model from file deepspeech-0.9.3-models-zh-CN.pbmm
TensorFlow: v2.3.0-6-g23ad988
DeepSpeech: v0.9.3-0-gf2e9c85
2021-09-04 02:47:32.705419: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Loaded model in 0.0436s.
Loading scorer from files deepspeech-0.9.3-models-zh-CN.scorer
Loaded scorer in 0.00114s.
Running inference.
同的祖母是一位佛教徒但他从二没有在未向前年国佛经有一天他前我是菜里杨聪认我在我一八年气派来结果动的管领流泪总合了他说乔丽多难受到这一个密绝大这么起就有机
Inference took 12.015s for 25.003s audio file.

ほう、何でもできるような気がしてきた。
まあ設計次第かな。

[音声認識] DeepSpeechでvideoのAutoSub(srtファイル)作成

– AutoSub is a CLI application to generate subtile file for any video using DeepSpeech.

### install
$ git clone https://github.com/abhirooptalasila/AutoSub
$ cd AutoSub

### virtual env
$ python3 -m venv sub
$ source sub/bin/activate
$ pip3 install -r requirements.txt
requirementsの中身は以下の通りです。

cycler==0.10.0
numpy
deepspeech==0.9.3
joblib==0.16.0
kiwisolver==1.2.0
pydub==0.23.1
pyparsing==2.4.7
python-dateutil==2.8.1
scikit-learn
scipy==1.4.1
six==1.15.0
tqdm==4.44.1

$ deactivate

### download model & scorer
$ wget https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.pbmm
$ wget https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer
$ mkdir audio output

$ sudo apt-get install ffmpeg
$ ffmpeg -version
ffmpeg version 4.2.4-1ubuntu0.1

今回はyoutubeの動画を使います

これを mp4に変換します。

$ python3 autosub/main.py –file hello.mp4
※main.pyで、modelとscorerのファイルを取得しているため、–model /home/AutoSub/deepspeech-0.9.3-models.pbmm –scorer /home/AutoSub/deepspeech-0.9.3-models.scorerは不要です。

for x in os.listdir():
        if x.endswith(".pbmm"):
            print("Model: ", os.path.join(os.getcwd(), x))
            ds_model = os.path.join(os.getcwd(), x)
        if x.endswith(".scorer"):
            print("Scorer: ", os.path.join(os.getcwd(), x))
            ds_scorer = os.path.join(os.getcwd(), x)

output/hello.srt

1
00:00:06,70 --> 00:00:15,60
a low and low and level how are you have low low and low how are you

2
00:00:16,10 --> 00:00:30,20
i do i am great i wonder for a good i grant it wonder for

3
00:00:32,45 --> 00:00:41,30
now at low halloway hallo hallo hallo how are you

4
00:00:41,90 --> 00:00:43,40
tired

5
00:00:43,55 --> 00:00:50,35
i am angry i'm not so good i'm tired

6
00:00:50,55 --> 00:00:55,95
i'm hungry and not so good

7
00:00:58,10 --> 00:01:07,15
love hollow hollow how are you have to have loved halloo are you

8
00:01:07,30 --> 00:01:16,65
how how low how do how are you allow a love as now how are you

これ、日本語でやりたい & リアルタイム出力したい