Crea un archivo de python donde abras un archivo txt y escribas texto dentro del archivo.
Despues abrir el archivo mediante codigo y mostrar el texto que contiene.
Crea un archivo de python donde abras un archivo txt y escribas texto dentro del archivo.
Despues abrir el archivo mediante codigo y mostrar el texto que contiene.
from gtts import gTTS def textoAudio(ficheroTexto, idioma, ficheroAudio): with open(ficheroTexto,"r") as fichero: texto = fichero.read() tts = gTTS(text=texto,lang=idioma) tts.save(ficheroAudio) print("He terminado de grabar el fichero de audio") textoAudio("texto.txt","ES","textoAudio.mp3")
import speech_recognition as srr = sr.Recognizer()#desde microfonowith sr.Microphone() as recurso:print("Dime algo ... ")audio = r.listen(recurso)try:texto = r.recognize_google(audio,language='es-ES')print("Esto es lo que has dicho : {}".format(texto))with open("audio.wav","wb") as fichero:fichero.write(audio.get_wav_data())except:print("Lo siento no te entendi")#desde fichero audioimport timewith sr.AudioFile("audio.wav") as recurso:audio = r.listen(recurso)try:print("Leyendo fichero de audio...")texto = r.recognize_google(audio,language='es-ES')time.sleep(0.5)print(texto)except:print("Lo siento ha ocurrido un error")
from io import
opentexto="Linea con texto\nSegunda linea\nTercera linea"
#abrimos fichero para escritura
wfichero=open('fichero.txt','w')
fichero.write(texto)fichero.close()
#abrimos fichero en modo lectura r
fichero=open('fichero.txt','r')
texto=fichero.read()
fichero.close()
print(texto)
cadena=input("Dame un texto - ")
condicion=len(cadena)>4 and len(cadena)<12
print("El texto es mayor que 4 y menor que 12 "+str(condicion))Obtenemos un texto usando "input" y lo guardamos en la variable cadena, despues comprobamos si la longitud (len) de cadena esta entre el intervalo que queremos, si es cierto condicion valdra True (verdadero), en caso contrario valdra False (falso).
# -*- coding: utf-8 -*-"""Created on Tue Aug 14 15:44:41 2018
@author: Jose"""
#importamos modulosimport pygame, sysfrom pygame.locals import *from random import randint
#init antes de usar pygamepygame.init()#declaramos ventana con alto anchoventana=pygame.display.set_mode((500,400))#titulopygame.display.set_caption("Time")#variablescolorFondo=(25,150,70)colorRectangulo1=(255,255,255)colorRectangulo2=(255,55,0)colorTexto=(125,10,200)velocidad=10
posX,posY=randint(1,400),randint(1,300)#rectangulosrectangulo1=pygame.Rect(5,10,70,40)rectangulo2=pygame.Rect(posX,posY,70,40)#textosfuente=pygame.font.SysFont('Arial',40)
#bucle ejecucion ventanawhile True: ventana.fill(colorFondo) #tiempo tiempo=pygame.time.get_ticks()/1000 #mostramos texto texto=fuente.render("Tiempo: "+str(tiempo),0,colorTexto) ventana.blit(texto,(140,140)) #dibujamos rectangulos pygame.draw.rect(ventana,colorRectangulo1,rectangulo1) pygame.draw.rect(ventana,colorRectangulo2,rectangulo2) #codigo seguir puntero raton posX,posY=pygame.mouse.get_pos() #lo centramos a rectangulo posX=posX-35 posY=posY-20 #cambiamos posicion rectangulo 1 rectangulo1.left=posX rectangulo1.top=posY #colision if rectangulo1.colliderect(rectangulo2): print("colisionando") posX,posY=randint(1,400),randint(1,300)
#cambiamos las coordenadas si se sale de limites if posX<0: posX=0 elif posX>430: posX=430 elif posY<0: posY=0 elif posY>360: posY=360 rectangulo2.left=posX-35 rectangulo2.top=posY-20 #control de eventos for evento in pygame.event.get(): if evento.type==QUIT: pygame.quit() sys.exit() #actualizamos segun pulse tecla flechas elif evento.type==pygame.KEYDOWN: if evento.key==K_LEFT: posX-=velocidad if posX<0: posX=0 elif evento.key==K_RIGHT: posX+=velocidad if posX>(500-70): posX=500-70 elif evento.key==K_UP: posY-=velocidad if posY<0: posY=0 elif evento.key==K_DOWN: posY+=velocidad if posY>360: posY=360 #actualiza ventana pygame.display.update()
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
public class fichero {
public File archivo=null;
public FileReader lector=null;
public BufferedReader br=null;
public FileWriter fichero=null;
public PrintWriter escritor=null;
void leer(String nombreArchivo){
try {
archivo=new File(nombreArchivo);
lector=new FileReader(archivo);
br=new BufferedReader(lector);
String linea;
while((linea=br.readLine())!=null){
System.out.println(linea);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
if(null!=lector){
lector.close();
}
}catch(Exception e2){
e2.printStackTrace();
}
}
}
void escribir(String nombreArchivo){
try {
fichero=new FileWriter(nombreArchivo);
escritor=new PrintWriter(fichero);
for(int i=0;i<15;i++){
escritor.println("Linea "+i);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
if(null!=escritor){
escritor.close();
}
}catch(Exception e2){
e2.printStackTrace();
}
}
}
}
public class principal {
public static void main(String[] args) {
fichero File=new fichero();
File.escribir("archivoTexto.txt");
File.leer("archivoTexto.txt");
}
}