Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Speach To Text To Translation(Azure版)

Speach To Text To Translation(Azure版)

「鹿児島Linux勉強会 2022.04(オンライン開催)」で発表
https://kagolug.connpass.com/event/244419/
source
https://gitlab.com/matoken/kagolug-2022.04/

Kenichiro MATOHARA

April 24, 2022
Tweet

More Decks by Kenichiro MATOHARA

Other Decks in Technology

Transcript

  1. Speach To Text To Translation(Azure Speach To Text To Translation(Azure

    版) 版) で 「色々聞 く」を発表 テキストを読み上げたり テキストを翻訳して読み上げたり YouTubeの文字起こし翻訳テキストを読み上げたり 文字起こしがYouTube頼りなので他のものも試したかった 東海道らぐとLinuxをはじめる春まつり(2022-04-16) slide/slide.adoc · master · Kenichiro MATOHARA / tokaidolug-2022.04 · GitLab 4 / 36
  2. Speach To Text Speach To Text 音声を文字起こし YouTubeは自動的に文字起こししてくれる 動画アップロードが必要 各社のSaaS

    GoogleはYouTubeと同じ? Web Speech API ※Experimental Chrome/Edge/Safari/WebView Android/Chrome Android/Safari on iOS/Samsung Internet localで動作する日本語対応のアプリケーションはない? Web Speech API - Web API | MDN 5 / 36
  3. Microsoft Azure Speech Service Microsoft Azure Speech Service 音声テキスト変換,テキスト読み上げ,音声翻訳,話者識別など SDK

    C#, C++, Java, JavaScript, Objective-C, Swift, Python Speech CLI(Docker/dotnet) 価格 Cognitive Services のSpeech Services | Microsoft Azure 6 / 36
  4. Docker版spx導入 Docker版spx導入  Docker版はマイク,スピーカーが直に使えない制限あり $ sudo docker pull msftspeech/spx $

    sudo docker image ls | pee "head -1" "grep spx" REPOSITORY TAG IMAGE ID CREATED SIZE msftspeech/spx latest d1ffdd590c84 9 days ago 969MB $ sudo docker run -it --rm msftspeech/spx help SPX - Azure Speech CLI, Version 1.21.0 Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. ______ ___ _ __ / ___// _ \ \/ / \___ \/ ___/ < /____ /_/ /__/\_\ USAGE: spx <command> [...] 8 / 36
  5. regionを登録 regionを登録 $ sudo docker run -it -v ~/Music:/data --rm

    msftspeech/spx \ config @region --set japanwest SPX - Azure Speech CLI, Version 1.21.0 Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. region (saved at '/data') japanwest 9 / 36
  6. keyを登録 keyを登録 hisotryに残らないよう頭に` 'を加えている $ sudo docker run -it -v

    ~/Music:/data --rm msftspeech/spx \ config @key --set deadbeef1234deadbeef1234deadbeef SPX - Azure Speech CLI, Version 1.21.0 Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. key (saved at '/data') deadbeef1234deadbeef1234deadbeef 10 / 36
  7. keyがhistoryに残っていないか確 keyがhistoryに残っていないか確 認.もしあったら消す 認.もしあったら消す $ history | grep 'msftspeech/spx config'

    372 sudo docker run -it --rm msftspeech/spx config @region --set japanwest 373 history | grep 'msftspeech/spx config' 11 / 36
  8. Text To Speachを試す Text To Speachを試す 既定値では英語 --voice オプションで各種言語でのスピーカー(話者) を指定できる.

    $ sudo docker run -it -v ~/Music:/data --rm msftspeech/spx \ synthesize --text "Enjoy using the Speech CLI." --audio output sample.wav $ ffprobe ~/Music/sample.wav 2>&1 | grep Input -A9 Input #0, wav, from '/home/ubuntu/Music/sample.wav': Duration: 00:00:02.88, bitrate: 256 kb/s Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, 1 channels, s16, 256 kb/s 12 / 36
  9. 日本語スピーカーの確認 日本語スピーカーの確認 spx synthesize --voices でjsonを含んだスピーカ一覧 $ sudo docker run

    -it -v ~/Music:/data --rm msftspeech/spx \ synthesize --voices | grep -E '^ \[' -A9999 | \ tr -d '^\ \ ' | jq '.[] | select(.Locale == "ja-JP")' { "Name": "MicrosoftServerSpeechTexttoSpeechVoice(ja-JP,NanamiNeural)", "DisplayName": "Nanami", "LocalName": "七海", "ShortName": "ja-JP-NanamiNeural", "Gender": "Female", "Locale": "ja-JP", "LocaleName": "Japanese(Japan)", "StyleList": [ "chat", "customerservice", "cheerful" ], "SampleRateHertz": "24000", "VoiceType": "Neural", "Status": "GA" } : 続く 13 / 36
  10. : 続き { "Name": "MicrosoftServerSpeechTexttoSpeechVoice(ja-JP,KeitaNeural)", "DisplayName": "Keita", "LocalName": "圭太", "ShortName":

    "ja-JP-KeitaNeural", "Gender": "Male", "Locale": "ja-JP", "LocaleName": "Japanese(Japan)", "SampleRateHertz": "24000", "VoiceType": "Neural", "Status": "GA" } 14 / 36
  11. 七海でTTS 七海でTTS $ sudo docker run -it -v ~/Music:/data --rm

    msftspeech/spx synthesize \ --text "日本語も話せます." --voice "ja-JP-NanamiNeural" --audio output japan.wav 15 / 36
  12. Speach To text Speach To text 英語 日本語 $ sudo

    docker run -it -v ~/Music:/data --rm msftspeech/spx recognize --file sample.wav $ cat ~/Music/output.132950280064316023.tsv audio.input.id recognizer.session.started.sessionid recognizer.recognized.result.text sample 8bcc7a9b0dd14132841cd19684202714 Enjoy using the speech CLI. $ sudo docker run -it -v ~/Music:/data --rm msftspeech/spx recognize --file japan.wav $ cat output.132950295870105988.tsv audio.input.id recognizer.session.started.sessionid recognizer.recognized.result.text japan 79ab40f8761049a3a8a572b0fbf084c2 Nihongo mohana semas 16 / 36
  13. 音声→テキスト翻訳 音声→テキスト翻訳 音声は.wavに変換しておく spx help translate language によると --source ,

    -- target は BCP-47 format $ sudo docker run -it -v ~/Music:/data --rm msftspeech/spx \ translate --file sample.wav --source en-US --target ja $ cat output.132950304946172724.tsv audio.input.id recognizer.session.started.sessionid recognizer.recognized.result.text sample 25bab9dffa7743ffbdff600e72b3f2ba Enjoy using the speech CLI. 音声 CLI を使用し 17 / 36
  14. 長い音声ファイル 長い音声ファイル 回線が細いとタイムアウトになった.RemoteのVPSで実行するとok 1.5h程の音声ファイル $ wget https://media.libreplanet.org/mgoblin_media/media_entries/2730/rms-2022-state-of-the-fr $ ffmpeg -i

    "rms-2022-state-of-the-free-software-movement.ogg" "rms-2022-state-of-the-free-sof $ sudo docker run -it -v ~/Music:/data --rm msftspeech/spx translate \ --file rms-2022-state-of-the-free-software-movement.wav --source en-US --target ja : SESSION STARTED: 4abfe53fee164f57bde9e1406764f37f 18 / 36
  15. 変換中 変換中 Connection CONNECTED... TRANSLATING into 'ja': 通常は起こりますが、もちろん (from '')

    TRANSLATING into 'ja': 通常起こるが、もちろんそれらは今起こっている (from '') TRANSLATING into 'ja': 通常起こるが、もちろん、彼らは今私は感謝したいと思います起こっています (from '') TRANSLATING into 'ja': 通常起こるが、もちろん、彼らは今起こっている私はあなたのすべてに感謝したいと思います TRANSLATING into 'ja': 通常起こるが、もちろん、彼らは今起こっている私は貢献しているあなたのすべてに感謝したい TRANSLATED into 'ja': 通常、それは起こりますが、もちろん起こっています。今、私は貢献した皆さん全員に感謝します appening. Now I'd to thank all of you who have contributed.') TRANSLATING into 'ja': 特にGNUソフトウェアに (from '') TRANSLATING into 'ja': 特にGNUソフトウェアだけでなく、 (from '') TRANSLATING into 'ja': 特にGNUソフトウェアだけでなく、他のソフトウェアにも (from '') TRANSLATED into 'ja': 特にGNUソフトウェアだけでなく、他の自由ソフトウェアにも。 (from 'Especially to GNU : 19 / 36
  16. 変換結果 変換結果 実時間よりも早く処理が終わった(1.5hの音声 → 1h) 1行で結果が帰ってくるようで少し扱いづらい $ ls -ltra |

    tail -2 -rw-r--r-- 1 root root 139499 Apr 21 16:55 output.132950309862177089.tsv -rw-r--r-- 1 root root 147947031 Apr 21 16:55 log-132950309862177089.log $ wc output.132950309862177089.tsv 2 10888 139499 output.132950309862177089.tsv $ head -1 output.132950309862177089.tsv | wc 1 4 134 $ head -2 output.132950309862177089.tsv | wc 2 10888 139499 20 / 36
  17. Linuxバイナリ(見当たらない) Linuxバイナリ(見当たらない) これ( )は2022-04-18時 点ではwindows版が降ってくるよう(英語ドキュメントも同じリンク) NuGet を使用せずに、Linux バイナリを .zip フ

    ァイルとしてダウンロードすることもできます。 spx-netcore-30-linux-x64.zip を新しい ~/spx ディレクトリに抽出し、バイナリに対する 「sudo chmod +r+x spx」を入力して、PATH システム変数に ~/spx パスを追加します。 https://aka.ms/speech/spx-linux 22 / 36
  18. install install NET Core 3.1 SDK 導入(snap) すでに他のバージョンが導入されているときは導入に失敗するので uninstallするか,unaliasして開けてあげる $

    sudo snap install dotnet-sdk --classic --channel=3.1 $ dotnet tool install --global Microsoft.CognitiveServices.Speech.CLI port: running "dotnet-runtime-60.dotnet" failed: cannot create transient scope: DBus error "org $ sudo snap unalias dotnet Removed: - dotnet-runtime-60.dotnet as dotnet $ snap install dotnet-sdk --classic --channel=3.1 dotnet-sdk (3.1/stable) 3.1.418 from Microsoft .NET Core (dotnetcore✓) installed 24 / 36
  19. NuGetでspx導入 NuGetでspx導入 $ dotnet tool install --global Microsoft.CognitiveServices.Speech.CLI Welcome to

    .NET Core 3.1! --------------------- SDK Version: 3.1.418 Telemetry --------- The .NET Core tools collect usage data in order to help us improve your experience. It is coll of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry ---------------- Explore documentation: https://aka.ms/dotnet-docs Report issues and find source on GitHub: https://github.com/dotnet/core Find out what's new: https://aka.ms/dotnet-whats-new Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs Write your first app: https://aka.ms/first-net-core-app -------------------------------------------------------------------------------------- Tools directory '/home/ubuntu/.dotnet/tools' is not currently on the PATH environment variable If you are using bash, you can add it to your profile by running the following command: cat << \EOF >> ~/.bash_profile # Add .NET Core SDK tools export PATH="$PATH:/home/ubuntu/.dotnet/tools" EOF You can add it to the current session by running the following command: export PATH="$PATH:/home/ubuntu/.dotnet/tools" 25 / 36
  20. PATHと環境変数設定する必要が PATHと環境変数設定する必要が あるよう あるよう PATHを通さないと $ spx help A fatal

    error occurred. The required library libhostfxr.so could not be found. If this is a self-contained application, that library should exist in [/home/ubuntu/.dotnet/to t.cognitiveservices.speech.cli/1.21.0/tools/netcoreapp3.1/any/]. If this is a framework-dependent application, install the runtime in the global location [/usr cify the runtime location or register the runtime location in [/etc/dotnet/install_location]. The .NET Core runtime can be found at: - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=ubuntu.20.04-x64 26 / 36
  21. 環境変数設定 環境変数設定 $ cat << \EOF >> ~/.bash_profile > #

    Add .NET Core SDK tools > export PATH="$PATH:/home/ubuntu/.dotnet/tools" > export DOTNET_ROOT=/snap/dotnet-sdk/current > EOF $ export PATH="$PATH:/home/ubuntu/.dotnet/tools" $ export DOTNET_ROOT=/snap/dotnet-sdk/current 27 / 36
  22. しかしエラー しかしエラー $ spx Process terminated. Couldn't find a valid

    ICU package installed on the system. Set the configu run with no globalization support. at System.Environment.FailFast(System.String) at System.Globalization.GlobalizationMode.GetGlobalizationInvariantMode() at System.Globalization.GlobalizationMode..cctor() at System.Globalization.CultureData.CreateCultureWithInvariantData() at System.Globalization.CultureData.get_Invariant() at System.Globalization.CultureInfo..cctor() at System.IO.TextWriter..cctor() at System.IO.StreamWriter..ctor(System.IO.Stream, System.Text.Encoding, Int32, Boolean) at System.Console.CreateOutputWriter(System.IO.Stream) at System.Console+<>c.<get_Out>b__26_0() at System.Threading.LazyInitializer.EnsureInitializedCore[[System.__Canon, System.Private.C bea7798e]](System.__Canon ByRef, System.Object ByRef, System.Func`1<System.__Canon>) at System.Threading.LazyInitializer.EnsureInitialized[[System.__Canon, System.Private.CoreL 798e]](System.__Canon ByRef, System.Object ByRef, System.Func`1<System.__Canon>) at System.Console.get_Out() at System.ConsolePal.EnsureInitializedCore() at System.ConsolePal+ControlCHandlerRegistrar.Register() at System.Console.add_CancelKeyPress(System.ConsoleCancelEventHandler) at Azure.AI.Speech.Tools.Carbonx2.Program.Main(System.String[]) Aborted (core dumped) 28 / 36
  23. DOTNET_SYSTEM_GLOBALIZA DOTNET_SYSTEM_GLOBALIZA TION_INVARIANT=1 も必要? TION_INVARIANT=1 も必要? グローバリゼーションの構成設定 - .NET |

    Microsoft Docs $ echo "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1" | tee -a ~/.profile DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 $ export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 $ spx help | head SPX - Azure Speech CLI, Version 1.21.0 Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. ______ ___ _ __ / ___// _ \ \/ / \___ \/ ___/ < /____ /_/ /__/\_\ USAGE: spx <command> [...] 29 / 36
  24. snd_aloop設定 snd_aloop設定 サウンドループバックデバイスを用意  Oracle Cloud VPSのUbuntu 20.04イメージでは linux- modules-extra-$(uname

    -r) の導入が必要 $ sudo modprobe -v snd_aloop $ lsmod | grep ^snd_aloop snd_aloop 28672 0 $ aplay -l | grep -i loop card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM] card 0: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM] 32 / 36
  25. spxで翻訳 spxで翻訳 orz $ spx translate --microphone --source en-US --target

    ja SPX - Azure Speech CLI, Version 1.21.0 Copyright (c) 2020 Microsoft Corporation. All Rights Reserved. audio.input.type=microphone diagnostics.config.log.file=log-{run.time}.log output.all.audio.input.id=true output.all.recognizer.recognized.result.text=true output.all.recognizer.recognized.result.translated.text=true output.all.recognizer.session.started.sessionid=true service.config.key= b028**************************** service.config.region=japanwest source.language.config=en-US target.language.config=ja x.command=translate Segmentation fault (core dumped) 34 / 36