jpenguin

speak selection Linux

Jun 28th, 2025 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Determine the clipboard command based on the session type
  4. if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
  5. clip_cmd="wl-paste --primary --no-newline"
  6. else
  7. clip_cmd="xclip -o"
  8. fi
  9.  
  10. # Temporary file for clipboard content
  11. temp_file="/tmp/clip.txt"
  12.  
  13. # Retrieve clipboard content and replace newlines with ,,,
  14. $clip_cmd | sed -z 's/\n/,,,/g' > "$temp_file"
  15.  
  16. # Check if the temporary file was created successfully
  17. if [ ! -f "$temp_file" ]; then
  18. notify-send "Failed to retrieve clipboard content."
  19. exit 1
  20. fi
  21.  
  22. # Read the temporary file, escape special characters, and pass to SpeechNote
  23. cat "$temp_file" | sed 's/[^a-zA-Z0-9]/\\&/g' | xargs flatpak run net.mkiol.SpeechNote --action start-reading-text --text
  24.  
  25. # Clean up the temporary file
  26. rm "$temp_file"
  27.  
Advertisement
Add Comment
Please, Sign In to add comment