Код: Выделить всё
#include
#include
LiquidCrystal_I2C lcd(0x20, 16, 2);
String buffer = "";
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.backlight(); // Turn on LCD backlight
}
void loop() {
while (Serial.available()) {
char c = Serial.read();
if (c == '\n') {
lcd.clear();
lcd.setCursor(0, 0);
// If text is longer than 16 characters, split across lines
lcd.print(buffer.substring(0, 16));
if (buffer.length() > 16) {
lcd.setCursor(0, 1);
lcd.print(buffer.substring(16, 32));
}
buffer = ""; // Reset buffer after displaying
} else {
buffer += c;
}
}
}
< /code>
Python Code для записи звука и отправки его в Assemblyai, получить текст, распечатать его и отправить в Arduino < /p>
import pyaudio
import wave
import requests
import json
import time
import uuid # For generating unique filenames
import os
import serial
ser = serial.Serial('COM3', 9600, timeout=1) # Adjust COM port as needed
# AssemblyAI API config
ASSEMBLYAI_API_KEY = 'f23aea7876d845bba0c9a3f282e8dfef' # timeout:
print("Transcription polling timed out.")
return None
time.sleep(poll_interval)
# Function to print the transcript
def print_transcript(transcript):
if transcript:
print(transcript)
else:
print("No transcription available.")
os.remove(nameoffile) # Clean up the audio file after transcription
def main():
audio_filename = generate_random_filename("wav")
record_audio(audio_filename, duration=5)
upload_url = upload_audio(audio_filename)
if not upload_url:
return
transcript_id = request_transcription(upload_url)
if not transcript_id:
return
transcript = poll_transcription(transcript_id)
print_transcript(transcript)
ser.write((transcript + '\n').encode('utf-8'))
ser.flush()
time.sleep(1) # Give some time for the Arduino to process the data
if __name__ == "__main__":
while True:
main()
< /code>
Это не отправляет его вообще. Речь идет не о ЖК -дисплее, потому что я попробовал serial.println Подробнее здесь: https://stackoverflow.com/questions/796 ... to-arduino