HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2016
0630
は?音声入力時の時間取得について4未解決


は?

リンク

2016/6/30(Thu) 15:18:48|NO.76034

外部マイクから「あー」とか「おー」とかを入力し、その入力された時間を
10m秒程度の単位で表示することはできないでしょうか。逆に、無音時間を
取得することはできないでしょうか。

http://hsp.tv/play/pforum.php?mode=pastwch&num=47567
http://hsp.tv/play/pforum.php?mode=pastwch&num=19810

などを見ましたが、いまひとつピンと来ません。
何分HSPにあまり詳しくないのでよろしくお願いします。



この記事に返信する


inovia

リンク

2016/6/30(Thu) 23:07:25|NO.76036

簡易的に作ってみたスクリプトです。
(というか、以前作ったものを焼き回してるだけ)
既定の録音デバイスの入力レベルを取得します。


// モジュール開始 #module #define CLSID_IMMDeviceEnumerator "{BCDE0395-E52F-467C-8E3D-C4579291692E}" #define IID_IMMDeviceEnumerator "{A95664D2-9614-4F35-A746-DE8DB63617E6}" #define IID_IMMDevice "{D666063F-1587-4E43-81F1-B948E807363F}" #define IID_IAudioEndpointVolume "{5CDF2C82-841E-4546-9722-0CF74078229A}" #define IID_IPerChannelDbLevel "{C2F8E001-F205-4BC9-99BC-C13B1E048CCB}" #define IID_IAudioMeterInformation "{C02216F6-8C67-4B5B-9D00-D008E73E0064}" // 再生デバイス #define ERender 0x00000000 // 録音デバイス #define ECapture 0x00000001 #define Console 0x00000000 #usecom IMMDeviceEnumerator IID_IMMDeviceEnumerator CLSID_IMMDeviceEnumerator #comfunc Enumerator_GetDefaultAudioEndpoint 4 int,int,var #usecom IMMDevice IID_IMMDevice CLSID_IMMDeviceEnumerator #comfunc Device_Activate 3 var,int,int,var #usecom IAudioEndpointVolume IID_IAudioEndpointVolume CLSID_IMMDeviceEnumerator #comfunc Volume_SetMasterVolumeLevelScalar 7 float,var #comfunc Volume_GetMasterVolumeLevelScalar 9 var #comfunc Volume_SetMute 14 int,int #comfunc Volume_GetMute 15 var #usecom IPerChannelDbLevel IID_IPerChannelDbLevel CLSID_IMMDeviceEnumerator #comfunc DbLevel_GetChannelCount 3 var #comfunc DbLevel_GetLevelRange 4 int,var,var,var #comfunc DbLevel_GetLevel 5 int,var #comfunc DbLevel_SetLevel 6 int,float,int #comfunc DbLevel_SetLevelUniform 7 float,int #comfunc DbLevel_SetLevelAllChannels 8 float,int,int #usecom IAudioMeterInformation IID_IAudioMeterInformation CLSID_IMMDeviceEnumerator #comfunc MeterInformation_GetPeakValue 3 var #comfunc MeterInformation_GetMeteringChannelCount 4 var #comfunc MeterInformation_GetChannelsPeakValues 5 int,var #comfunc MeterInformation_QueryHardwareSupport 6 var #defcfunc todouble int p1 temp = 0.0 lpoke temp, 4, (p1 & 0x80000000) | (((p1 & 0x7fffffff) >> 3) + ((p1 & 0x7fffffff) ! 0) * 0x38000000) lpoke temp, 0, p1 << 29 return temp #deffunc local _OpenDevice newcom pMMDeviceEnumerator,IMMDeviceEnumerator if varuse(pMMDeviceEnumerator) = 0 : _CloseDevice : return -1 newcom pMMDevice,IMMDevice,-1,0 newcom pAudioEndpointVolume,IAudioEndpointVolume,-1,0 newcom pAudioMeterInformation,IAudioMeterInformation,-1,0 Enumerator_GetDefaultAudioEndpoint pMMDeviceEnumerator,ECapture,Console,pMMDevice if varuse(pMMDevice) = 0 : _CloseDevice : return -2 guid = 0x5CDF2C82 , 0x4546841E , 0xF70C2297 , 0x9A227840 Device_Activate pMMDevice,guid,1,0,pAudioEndpointVolume if varuse(pAudioEndpointVolume) = 0 : _CloseDevice : return -3 guid = 0xC02216F6, 0x4B5B8C67, 0x08D0009D, 0x64003EE7 Device_Activate pMMDevice,guid,1,0,pAudioMeterInformation if varuse(pAudioMeterInformation) = 0 : _CloseDevice : return -4 return 0 #deffunc local _CloseDevice if vartype(pAudioMeterInformation) = 6{ if varuse(pAudioMeterInformation) != 0{ delcom pAudioMeterInformation } } if vartype(pAudioEndpointVolume) = 6{ if varuse(pAudioEndpointVolume) != 0{ delcom pAudioEndpointVolume } } if vartype(pMMDevice) = 6{ if varuse(pMMDevice) != 0{ delcom pMMDevice } } if vartype(pMMDeviceEnumerator) = 6{ if varuse(pMMDeviceEnumerator) != 0{ delcom pMMDeviceEnumerator } } return #defcfunc GetPeakValueVista _OpenDevice if stat<0 : return stat res = 0 MeterInformation_GetPeakValue pAudioMeterInformation, res _CloseDevice return todouble(res) #defcfunc GetChannelsPeakValuesVista int ch _OpenDevice if stat<0 : return stat res = 0 MeterInformation_GetChannelsPeakValues pAudioMeterInformation, ch, res _CloseDevice return todouble(res) #defcfunc GetMeteringChannelCountVista _OpenDevice if stat<0 : return stat res = 0 MeterInformation_GetMeteringChannelCount pAudioMeterInformation, res _CloseDevice return res #global // モジュール終了 // サンプル開始 #include "winmm.as" width 200, 100 // マイクだと雑音等も入るので、0.1 ぐらい? // ステレオミキサーとかであれば、 0.00 とか 0.01 で良いと思います 有音判定しきい値 = 0.10 無音ms = 0 有音ms = 0 差分ms = 0 // 入力レベルの範囲は 0.0 〜 1.0 入力レベル = 0.0 repeat timeGetTime 開始ms = stat redraw 1 : wait 0 : redraw 0 入力レベル = GetPeakValueVista() if (有音判定しきい値 < 入力レベル) { // 有音 有音ms += 差分ms ;無音ms = 0 }else{ // 無音 無音ms += 差分ms ;有音ms = 0 } pos 0, 0 : color 255, 255, 255 : boxf : color mes "有音:" + strf("%02.1f", 1.0 * 有音ms / 1000) + " 秒" mes "無音:" + strf("%02.1f", 1.0 * 無音ms / 1000) + " 秒" mes "入力レベル:" + strf("%02.2f", 入力レベル * 100) + " %" mes "差分:" + 差分ms + " ms" timeGetTime 終了ms = stat 差分ms = 終了ms - 開始ms loop // サンプル終了



は?

リンク

2016/7/1(Fri) 16:07:35|NO.76038

HSP3.4でコンパイルしましたが
「???(94) : error 2 : 文法が間違っています (94行目)」
ひっかかってしまいました。
45行目「#deffunc local _OpenDevice」
との関係かと思いますが、解決できません。
よろしく御教授ください。



n

リンク

2016/7/1(Fri) 16:33:23|NO.76039

local消せばいいだけかと



暇人

リンク

2016/7/1(Fri) 19:08:56|NO.76040

HSP3.5以上を使うとか
#deffunc local の命令定義を後ろに置くとか
#moduleに名前を付けてローカル命令使用時に @モジュール命 を付ける等



ONION software Copyright 1997-2023(c) All rights reserved.