├── LICENSE
├── README.md
├── conv.sh
├── esp8266-wifi-mic.ino
├── pubsubclientesp8266.zip
├── speech.py
└── test16.wav
/LICENSE:
--------------------------------------------------------------------------------
1 | # esp8266-wifi-microphone
2 |
3 | Project name: esp8266-wifi-microphone
4 | Copyright (C) 2018 hjltu@ya.ru
5 |
6 | esp8266-wifi-microphone is free software: you can redistribute
7 | it and/or modifyit under the terms of the GNU General Public License
8 | as published by the Free Software Foundation, either version 3 of the
9 | License, or (at your option) any later version.
10 |
11 | esp8266-wifi-microphone is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # esp8266-wifi-microphone
2 |
3 | **esp8266-wifi-mic.ino** - Arduino IDE file for esp8266,
4 | nodemcu or wemos d1 mini.
5 |
6 | **conv.sh** - convert from raw audio to 16-bit WAV and
7 | receive text from Yandex SpeechKit Cloud.
8 |
9 | **test16.wav** - sample.
10 |
11 | **speech.py** - python3 script speech2text.
12 |
13 | The microphone(max4466) is connected to A0 in esp8266
14 | esp8266 transmit raw audio to MQTT server.
15 | conv.sh converting audio and with yandex speechkit getting text.
16 |
17 | Video: [Youtube](https://youtu.be/rU_Pw9Jb_PM)
18 |
19 | tip: use node-red to save the RAW file
20 |
--------------------------------------------------------------------------------
/conv.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | RAW="test.raw"
3 | WAV="test.wav"
4 | WAV16="test16.wav"
5 |
6 | UUID="your yandex uuid"
7 | KEY="your yandex key"
8 |
9 | if [ -s $RAW ];then
10 | ffmpeg -f u8 -ar 10000 -ac 1 -i $RAW -y $WAV
11 | ffmpeg -i $WAV -ar 16000 -y $WAV16
12 | echo -n > $RAW
13 | mpv $WAV
14 |
15 | curl -X POST -H "Content-Type: audio/x-wav" --data-binary "@$WAV16" \
16 | "https://asr.yandex.net/asr_xml?uuid=$UUID&key=$KEY&topic=queries" | \
17 | sed -n -e '/variant\.*>/,/<\/variant/p' | \
18 | sed '/<\/variant>/!d' | \
19 | sed 's///' | \
20 | sed 's/<\(.*\)//' | \
21 | sed 's/\s//'
22 |
23 |
24 | else
25 | echo "empty raw"
26 | fi
27 |
28 |
--------------------------------------------------------------------------------
/esp8266-wifi-mic.ino:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | const char *ssid = "SSID"; // Change it
6 | const char *pass = "PASS"; // Change it
7 |
8 | WiFiClient wclient;
9 | IPAddress mqtt_server(192,168,0,10); // Change it
10 | PubSubClient client(wclient, mqtt_server);
11 |
12 | // client name
13 | String str_name="nodemcu";
14 |
15 | String str_topic = String("/" + str_name + "/out/rec");
16 | String str_payload;
17 |
18 | bool bt;
19 | byte rec;
20 | int count;
21 | //char stream[24000];
22 |
23 | void setup()
24 | {
25 | Serial.begin(115200);
26 | Serial.println(0); //start
27 | WiFi.mode(WIFI_STA);
28 | WiFi.begin(ssid, pass);
29 | pinMode(0,INPUT_PULLUP); // bt D3
30 | pinMode(16,OUTPUT); // rele D0 led
31 | }
32 |
33 | void loop()
34 | {
35 | my_connect();
36 | if(client.connected())
37 | {
38 | my_button();
39 | my_analog();
40 | }
41 |
42 | }
43 |
44 | void my_connect()
45 | {
46 | if (WiFi.status() != WL_CONNECTED)
47 | {
48 | Serial.println(1); //Connecting to
49 | WiFi.begin(ssid, pass);
50 |
51 | if(WiFi.waitForConnectResult() != WL_CONNECTED)
52 | {
53 | Serial.println(2); //WiFi NOT connected
54 | if(digitalRead(16)==LOW)
55 | digitalWrite(16,HIGH);
56 | return;
57 | }
58 | Serial.println(3); //WiFi connected
59 | }
60 | if(WiFi.status() == WL_CONNECTED)
61 | {
62 | if(!client.connected())
63 | {
64 | Serial.println(4); //Connecting to MQTT server
65 | if(client.connect(str_name))
66 | {
67 | Serial.println(5); //Connected to MQTT server
68 | }
69 | else
70 | {
71 | Serial.println(6); //Could not connect to MQTT server
72 | if(digitalRead(16)==LOW)
73 | digitalWrite(16,HIGH);
74 | }
75 | }
76 | if(client.connected())
77 | {
78 | client.loop();
79 | if(digitalRead(16)==HIGH)
80 | digitalWrite(16,LOW);
81 | }
82 | }
83 | }
84 |
85 | void my_print()
86 | {
87 | //Serial.println(millis());
88 | client.publish(str_topic,str_payload);
89 | str_payload="";
90 | //Serial.println(millis());
91 | }
92 |
93 | void my_button()
94 | {
95 | if(digitalRead(0)==LOW && count<15)
96 | count++;
97 | if(digitalRead(0)==HIGH && count>0)
98 | count--;
99 | if(count>10 && bt==false)
100 | bt=true;
101 | if(count<5 && bt==true)
102 | bt=false;
103 | }
104 |
105 | void my_analog()
106 | {
107 | if(bt==true)
108 | {
109 | //Serial.println(millis());
110 | my_record();
111 | //Serial.println(millis());
112 | }
113 | }
114 |
115 | void my_record()
116 | {
117 | bt=false;
118 | for(int y=0;y<11;y++)
119 | {
120 | for(int i=0;i<1000;i++)
121 | {
122 | //rec = char(analogRead(A0)/4);
123 | //if(rec<200)
124 | //str_payload += rec;
125 | str_payload += char(analogRead(A0)/4);
126 | //delayMicroseconds(25); //125-8kb
127 | }
128 | my_print();
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/pubsubclientesp8266.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hjltu/esp8266-wifi-microphone/e968a0824b6b2c6830524f7a2c74d9e8fa879fb0/pubsubclientesp8266.zip
--------------------------------------------------------------------------------
/speech.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | """
4 | sudo pip3 install SpeechRecognition
5 | """
6 |
7 | import speech_recognition as sr
8 |
9 |
10 | r = sr.Recognizer()
11 |
12 | sample = sr.AudioFile('test16.wav')
13 | with sample as source:
14 | audio = r.record(source)
15 |
16 | print(r.recognize_google(audio, language="ru_RU"))
17 |
--------------------------------------------------------------------------------
/test16.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hjltu/esp8266-wifi-microphone/e968a0824b6b2c6830524f7a2c74d9e8fa879fb0/test16.wav
--------------------------------------------------------------------------------