@@ -49,7 +49,7 @@ def cmd_list_audio_interfaces
49
49
end
50
50
end
51
51
52
- def cmd_mic_start ( mic_index = 0 , start_delay = 4096 )
52
+ def cmd_mic_start ( start_delay = 4096 )
53
53
print_status ( "Streaming mic audio channel..." )
54
54
55
55
if client . mic . mic_list . length == 0
@@ -65,16 +65,62 @@ def cmd_mic_start(mic_index=0, start_delay=4096)
65
65
print_status ( "Audio File: #{ stream_path } " )
66
66
print_status ( "Streaming..." )
67
67
68
- client . mic_start ( mic_index , start_delay )
69
- end
68
+ begin
69
+ client . mic . mic_start
70
+ mic_started = true
71
+ ::Timeout . timeout ( duration ) do
72
+ ::File . open ( stream_path , 'wb' ) do |outfd |
73
+ numchannels = 1
74
+ sampleratehz = 11025
75
+ bitspersample = 16
76
+ datasize = 2000000000
77
+ subchunk1size = 16
78
+ chunksize = 4 + ( 8 + subchunk1size ) + ( 8 + datasize )
79
+ byterate = sampleratehz * numchannels * bitspersample / 8
80
+ blockalign = numchannels * bitspersample / 8
70
81
71
- def cmd_mic_stop
72
- client . mic . mic_stop
82
+ BinData ::Int32be . new ( 0x52494646 ) . write ( outfd ) # ChunkID: "RIFF"
83
+ BinData ::Int32le . new ( chunksize ) . write ( outfd ) # ChunkSize
84
+ BinData ::Int32be . new ( 0x57415645 ) . write ( outfd ) # Format: "WAVE"
85
+ BinData ::Int32be . new ( 0x666d7420 ) . write ( outfd ) # SubChunk1ID: "fmt "
86
+ BinData ::Int32le . new ( 16 ) . write ( outfd ) # SubChunk1Size
87
+ BinData ::Int16le . new ( 1 ) . write ( outfd ) # AudioFormat
88
+ BinData ::Int16le . new ( numchannels ) . write ( outfd ) # NumChannels
89
+ BinData ::Int32le . new ( sampleratehz ) . write ( outfd ) # SampleRate
90
+ BinData ::Int32le . new ( byterate ) . write ( outfd ) # ByteRate
91
+ BinData ::Int16le . new ( blockalign ) . write ( outfd ) # BlockAlign
92
+ BinData ::Int16le . new ( bitspersample ) . write ( outfd ) # BitsPerSample
93
+ BinData ::Int32be . new ( 0x64617461 ) . write ( outfd ) # SubChunk2ID: "data"
94
+ BinData ::Int32le . new ( datasize ) . write ( outfd ) # SubChunk2Size
95
+ end
96
+ stream_index = 0
97
+ while client do
98
+ if stream_index == start_delay
99
+ cmd_listen ( stream_path )
100
+ end
101
+ data = client . mic . mic_get_frame ( quality )
102
+ if data
103
+ ::File . open ( stream_path , 'a' ) do |f |
104
+ f . write ( data )
105
+ end
106
+ data = nil
107
+ end
108
+ stream_index += 1
109
+ end
110
+ end
111
+ rescue ::Timeout ::Error
112
+ ensure
113
+ client . mic . mic_stop if mic_started
114
+ end
73
115
end
74
116
75
117
def cmd_listen ( stream_path )
76
118
Rex ::Compat . open_webrtc_browser ( "file://#{ ::File . absolute_path ( stream_path ) } " )
77
119
end
120
+
121
+ def cmd_mic_stop
122
+ client . mic . mic_stop
123
+ end
78
124
end
79
125
end
80
126
end
0 commit comments